Here's the problem:
is=this.getClass().getResourceAsStream("/config/config.properties");
This is not as normal file system read. It is reading a resource from the classpath using a path that is relative a directory or JAR file that is on the classpath. The path is a resource path, not a file system path.
If you want to write to that file:
It must be a free-standing file, not a JAR or ZIP file entry or something like that.
It mustn't be read-only ... or locked.
You need to know the actual absolute or relative file system pathname that corresponds to the resource path. (Because the resource API methods don't provide a way to open a resource for writing.)
Instead, you have tried to use the resource path to identify the file when you open it to write. (The FileOutputStream
class requires a file system path.)
Basically, you are going to have to redesign this. Updating things on the resource path is typically difficult, and sometimes impossible. Also, you appear to be refering to the resource in a /src/...
location, which won't be on the classpath when your application is deployed. (I assume that you won't expect your users to download, install and learn to use a Java IDE so that they can run your app!)
A better idea is to put the properties file into the application's installation directory, or the user's home directory. Then you figure out a way for the application to find out where that is. (For example, if you are launching the app using a wrapper script, the script could pass the installation directory path to your app using a -D
option.
Another alternative is to use the Java settings API which can store the settings in a (platform specific) standard place in the file system.