0

I am using following code to load resource from my project.

ResourceBundle props=ResourceBundle.getBundle("db");

This is loading fine. But after this loading i'm modifying the same file and trying to get the latest contents from the file. Again using the above code to load the same file is returning the old file content. I think its loading from cache. How can we reload this resource again?

1 Answers1

0

Yes, Resource bundle instances created by the getBundle factory methods are cached by default, So you can avoid that by following ways

  1. Clear cache. ResourceBundle.clearCache(ClassLoader loader)
  2. manage the lifetime of cached resource bundle instances using time-to-live values. Using method Class ResourceBundle.Control public long getTimeToLive(String baseName, Locale locale)

  3. specify not to cache resource bundle instances. Using method Class ResourceBundle.Control public boolean needsReload(String baseName, Locale locale, String format, ClassLoader loader, ResourceBundle bundle, long loadTime)

Deepak Tripathi
  • 600
  • 2
  • 4
  • 22
  • I tried clearCache() it is not working still i'm getting old changes after writing new content to the file. – Maninder Jeet Singh Mar 24 '17 at 10:54
  • I'm running maven command and it created a folder with all the compiled code. But I am modifying resource in folder src/test/resource. But resource bundle is loading resource from target folder. Do you have any solution for this ? – Maninder Jeet Singh Mar 24 '17 at 12:24
  • all output files will be housed in target folder. So may be if you are changing text in file you can make use of classpath. reference http://stackoverflow.com/questions/1464291/how-to-really-read-text-file-from-classpath-in-java – Deepak Tripathi Mar 24 '17 at 12:48
  • thanks his is resolved. Issue was with classpath loading – Maninder Jeet Singh Mar 27 '17 at 05:39