Method store of java.util.Properties not storing the properties in the order retrieved.
4 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Smita_Acharya
Posted On:   Friday, June 4, 2004 07:05 AM


The following is the piece of code am using.

FileInputStream in = new FileInputStream(org_fname);

Properties props = new Properties();

props.load(in);

FileOutputStream output = new FileOutputStream(encrypt_fname);

props.store(output,"No header");

output.close();



But the properties are not getting stored in the order in which they are retrieved, and the string ":" in any of property values is getting replaced with ":"

Re: Method store of java.util.Properties not storing the properties in the order retrieved.

Posted By:   Stephen_Ostermiller  
Posted On:   Tuesday, June 8, 2004 02:31 AM

I wrote a propreties work alike: http://ostermiller.org/utils/UberProperties.html It stores them in alpha order, but I would like to add a way to store them in the order in which they were read. It would just require a list data structure of the keys. Its open source if you are interested.

Re: Method store of java.util.Properties not storing the properties in the order retrieved.

Posted By:   JavaPrasad_P  
Posted On:   Friday, June 4, 2004 05:12 PM

You can read data into java.util.LinkedHashMap object to gaurantee the order.


This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map


Prasad

Re: Method store of java.util.Properties not storing the properties in the order retrieved.

Posted By:   Sean_Owen  
Posted On:   Friday, June 4, 2004 07:13 AM

Yes, java.util.Properties does not guarantee anything about the order in which properties are written to a file. Also, it will escape certain characters with a backslash to ensure that they are read in again correctly. Please see the javadoc for java.util.Properties.store().



If you want different behavior I believe you'll need to write some code to write out the properties yourself. If you're clever you could do this by subclassing Properites and overriding a few key methods.

Re: Method store of java.util.Properties not storing the properties in the order retrieved.

Posted By:   Christopher_Koenigsberg  
Posted On:   Friday, June 4, 2004 07:12 AM

Sounds like it is working correctly. What is the problem?
About | Sitemap | Contact