jeudi 30 avril 2015

Why does FileOutputStream corrupt my properties file?

I have encountered a weird problem while coding a class to read/write settings. I'm using a properties file. In a prepare()-method, I want to load the in-/output streams to the file. When I only load the input stream everything works fine, but once I try to load the output stream as well, something breaks. Whatever I try to read through a properties object, it gives back null. Even if I then get rid off the output stream again, and start the program only with the input stream, it still gives back null. If I then create a new properties file (copy/paste the content), it works again (without output stream).

My guess is, the output stream corrupts the file in some way (even though I have no clue how). I can still open the file in a text editor.

Here's the code:

File configFile = new File(SettingsProvider.class.getResource("/res/ServerConfig.properties").toURI());
streamIn = new FileInputStream(configFile);
streamOut = new FileOutputStream(configFile);
props = new Properties();
props.load(streamIn);

Aucun commentaire:

Enregistrer un commentaire