'Property file resets after loading

I want to add some values to an existing property file, but the file resets everytime I run the program and only the new values are in the file.

I know there are many people with the same problem out there, but I looked at solutions on the internet and nothing worked for me. Many solutions said that you have to call .load() before setting properties and storing, but it's seems that calling .load() doesn't work for me.

This is my code:

public class FxCheckLocalisation {
    private final File       notFoundPropertiesFile        = new File(
            "C:\\Projekte\\core8\\remote\\src\\main\\resources\\lang\\de\\core_missing_localisation.properties");
    private final Properties notFoundProperties            = new Properties();

    private final File       newLocalisationPropertiesFile = new File(
            "C:\\Projekte\\core8\\remote\\src\\main\\resources\\lang\\de\\core_masks.properties");
    private final Properties newLocalisationProperties     = new Properties();

    private final File       oldLocalisationPropertiesFile = new File(
            "C:\\Projekte\\core8\\remote\\src\\main\\resources\\lang\\de\\core_old.properties");
    private final Properties oldLocalisationProperties     = new Properties();

    public static void main(final String[] args) {
        final FxCheckLocalisation checkLocalisation = new FxCheckLocalisation();

        checkLocalisation.checkProperties();
    }

    private void checkProperties() {
        try (FileInputStream fileReaderNotFound = new FileInputStream(this.notFoundPropertiesFile);
                FileInputStream fileReaderOld = new FileInputStream(this.oldLocalisationPropertiesFile);
                FileInputStream fileReaderNew = new FileInputStream(this.newLocalisationPropertiesFile)) {
            this.notFoundProperties.load(fileReaderNotFound);
            this.oldLocalisationProperties.load(fileReaderOld);
            this.newLocalisationProperties.load(fileReaderNew);

            this.notFoundProperties.forEach((keyNotFound, valueNotFound) -> {
                if ((this.oldLocalisationProperties.getProperty(keyNotFound.toString()) != null)
                        && (this.newLocalisationProperties.getProperty(keyNotFound.toString()) == null)) {
                    this.newLocalisationProperties.setProperty(keyNotFound.toString(),
                            this.oldLocalisationProperties.getProperty(keyNotFound.toString()));
                }
            });

            final FileOutputStream outputStream = new FileOutputStream(this.newLocalisationPropertiesFile);
            this.newLocalisationProperties.store(outputStream, null);
            outputStream.close();
        } catch (final IOException e) {
            e.printStackTrace();
        }
    }
}

The code cycles trough all not found properties and searches them inside oldLocalisationProperties. If it exists it adds this property to newLocalisationProperties.

Can anyone help me and tell me why my file resets everytime and only the new values are shown. Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source