Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use of ResourceBundle for properties

 
Stuart Bell
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My understanding of using the ResourceBundle class for reading in a Properties file is that it will only read the properties in once and once only. I wish to read in a properties file everytime so that we can change the value on the fly without having to restart the application so that the change will take effect.

Is there anyway of doing this within the ResourceBundle itself? I am using Java 1.3.1.

I have put a piece of code together that does work, but I am not certain it is the most efficient way of doing it:

URL url = getClass().getClassLoader().getResource("garbageCollection.properties");
InputStream stream = url.openStream();
InputStreamReader isReader = new InputStreamReader(stream);
BufferedReader buffer = new BufferedReader(isReader);
String lineRead = null;

while((lineRead = buffer.readLine()) != null) {
if (lineRead.indexOf("confirm.payment.invoke.gc") != -1) {
StringTokenizer tokenizer = new StringTokenizer(lineRead, "=");
tokenizer.nextToken(); // skip the first value
invokeGC = tokenizer.nextToken(); // read in the second
}
}

Any words of advice or thoughts?

Thanks,


Stuart
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ResourceBundle's getBundle methods do cache their results -- take a peek into the source code to see. Unfortunately, there's no "flush" method in the API, and I'm not brave enough play around with class loaders to get around that.

It doesn't seem like you are using ResourceBundles for what theye are intended -- multi-language, multi-locale support. Why not work directly with java.util.Properies and its load method -- I'm sure there is no caching there.
 
Stuart Bell
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply and confirming my thoughts. I'll investigate Properties further.

Cheers,


Stuart
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic