views:

424

answers:

2

Hi %,

playing around with a property file i figured that there seems to be a limitation of 40char to save in a single property.

I do the following:

File configFile = new File("config.properties");

Properties props = new Properties();
props.put( "cc_server", "sort_of_a_long_string_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
FileOutputStream fos = new FileOutputStream( configFile );
PrintWriter pw = new PrintWriter( fos );
props.list( pw );
pw.flush();
pw.close();   
System.out.println("done.");

The result is, that only the first 37char get saved, extended by "...". I debuged that the PropertiesHash's got the right values, the writing to the file seems to be the problem.

Is there a way to extend / switch off this limitation?

tia

 K
+7  A: 

There is no such limit

Since you mention "..." i have this question: are you displaying the value in a JLabel ? The "..." is a typical way of a JLabel rendering a String thats too long.

There also is an easier way to save Properties

File propertiesfile=new File("fileName.props");
propstosave.store(new FileOutputStream(propertiesfile), "groupnames");
Peter
Hi,I don't display the value at all. Checking the actual config filesshows me that the value that is saved is allready truncated and extended by the mentioned dots.Using your 'storeApproach' resolved the issue, thx a bunch! KB
KB22
+11  A: 

you are using a debugging feature to save the file. The list() method is not intented for saving properties to a file, you should use the store() method instead:

File configFile = new File("config.properties");
Properties props = new Properties();
props.put("cc_server", "sort_of_a_long_string_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
props.store(new FileOutputStream(configFile),"aaa");
dfa
list method is useful for debugging purpose only.
adatapost