Changing values in a properties file

Hi,

I'm working in a Struts environment and I am trying to open a .properties file in my WEB-INF/classes/ (*.properties) directory and allow the user to change those values and write them back.

I access the properties by pulling them out in a Map:

Locale locale = LocaleContextHolder.getLocale();

ResourceBundle resBundle = ResourceBundle.getBundle(SP_PROPERTIES_FILE,locale);

Enumeration propertyKeys = resBundle.getKeys();

Map spProperties =new HashMap();

while (propertyKeys.hasMoreElements()){

String key = (String) propertyKeys.nextElement();

if(key !=null){

key = key.trim();

}

String value = resBundle.getString(key);

if(value !=null ){

value = value.trim();

}

spProperties.put(key, value);

}

I then change the values depending on their keys, but it is after this step I am unsure how perform the write back.

Thanks,

[1303 byte] By [Graeme_BiPa] at [2007-11-27 8:18:18]
# 1

A ResourceBundle is a read-only object. It doesn't provide any methods for updating. If you want to allow your users to update the data, the code will have to update the underlying properties file. This also is impossible if your application server doesn't expand the application but runs it from a WAR or EAR archive.

[Edit] And even at that, allowing users to update properties files in a multi-user environment is risky -- if two users update the file at the same time, it's easy to lose one of the updates.

DrClapa at 2007-7-12 20:03:47 > top of Java-index,Java Essentials,Java Programming...