File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Use of ResourceBundle for properties Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Use of ResourceBundle for properties" Watch "Use of ResourceBundle for properties" New topic

Use of ResourceBundle for properties

Stuart Bell

Joined: Sep 17, 2004
Posts: 22

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("");
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?



SCJP (Java 2)<br />SCJD<br />SCWCD
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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.

There is no emoticon for what I am feeling!
Stuart Bell

Joined: Sep 17, 2004
Posts: 22
Thanks for your reply and confirming my thoughts. I'll investigate Properties further.


I agree. Here's the link:
subject: Use of ResourceBundle for properties
It's not a secret anymore!