Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Maintaining order of properties in a properties file

807589Jul 2 2007 — edited Dec 13 2008
Hello everyone,

I am dynamically creating .properties files based on the contents of one .properties file.

I first save the .properties file that contains only keys (not values) using file copy as illustrated here : http://www.exampledepot.com/egs/java.nio/File2File.html

The above method works well, the order of the keys doesn't change.

However, after creating a copy of the file, I load and store values dynamically to it as in the snippet below
            Properties myProperties = new Properties();

            myProperties .load( new FileInputStream( "fileName") );

            emailBeanProperties.setProperty( "myKey", "myValue" );

            emailBeanProperties.store( new FileOutputStream( "fileName"), "" );
When I run the above code the order of the keys in the properties files changes, also the lines in between the keys disappear.

Would anyone know how to retain the original order and blank lines in which the keys were first specified when storing values into properties files dynamically?

I will try to test if specifying all values solves this problem

Any help is appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 10 2009
Added on Jul 2 2007
28 comments
3,218 views