aspose file tools*
The moose likes Beginning Java and the fly likes how can i get the path from which resource bundle gets its bundle file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how can i get the path from which resource bundle gets its bundle file " Watch "how can i get the path from which resource bundle gets its bundle file " New topic
Author

how can i get the path from which resource bundle gets its bundle file

Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
Hello all
im using resource bundle to load values from properties files , i like to know
from where the resource bundle load its properties file in the classpath
is there away to do this ?
Minh Tran
Greenhorn

Joined: Jun 03, 2007
Posts: 19
It is safer and more securer if you use ResourceBundle to load .properties file. You can write it by yourself as simple way. It use classLoader and stream to load file as its locale


SCJP 1.4, SCWCD 1.4<br />email:mobject@gmail.com
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
hi
i do use RB to load the files , i just need to know from whice path i load them
Abdul Kader
Ranch Hand

Joined: Apr 11, 2007
Posts: 115
Resource bundle will check the class path and compare with your file name. if it able to match then it will load the file as the property file. here the location is all about the class path.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I wonder if you could create a custom ClassLoader that calls a listener any time it succeeds ...

That gives you all you need to map names to URLs.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
i dont understand how can i implement it so it will give me the path
of the prop file the RB found
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I left a lot out of that suggestion.

First, read up on ClassLoaders. You can write a custom ClassLoader that extends URLClassLoader and override the method I showed before. When it succesfully loads a class, it calls a listener object with name and full classname. You might pass that listener object to your ClassLoader in the ClassLoader constructor.

Then pass your own ClassLoader to ResourceBundle.get().

Now ResourceBundle calls the ClassLoader over and over, once for each candidate name that it might load. When it actually finds a file, the loader will call your listener and you save off the information. When ResourceBundle returns you a bundle, the info you saved should be the latest file loaded.

I can't guarantee this will work out ... give it a try and see!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how can i get the path from which resource bundle gets its bundle file