This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes getting data from files in your CLASSPATH Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "getting data from files in your CLASSPATH" Watch "getting data from files in your CLASSPATH" New topic
Author

getting data from files in your CLASSPATH

Felix Ulrich
Greenhorn

Joined: Jun 11, 2001
Posts: 9
Hi gang
I'd like to retrieve information from files in the classpath of the running VM - e.g. .properties files. Is there a way of doing this without having to supply the physical location of the file on disk?
Thanks
Felix.
Mohamed Yousuff
Ranch Hand

Joined: Jun 23, 2001
Posts: 73

You can get the information of your environment using System.getProperties(). The return type is java.util.Properties. I hope you can get information on the classpath also using this. Good Luck
Originally posted by Felix Ulrich:
Hi gang
I'd like to retrieve information from files in the classpath of the running VM - e.g. .properties files. Is there a way of doing this without having to supply the physical location of the file on disk?
Thanks
Felix.

Felix Ulrich
Greenhorn

Joined: Jun 11, 2001
Posts: 9
I'm afraid that's not much help - it only get System properties - e.g. user.dir, os.version, etc. I want to include a something.conf file in my classpath, and then load it from within my application, without using the File stuff in java.io.
Felix.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

THere's a get resourec or some such in either Class or ClassLoader (CL is my guess). I used it just the other day.
(Sorry this is deliberately vague but I'm tired and it's kinder than rtfm... )
Dave
Felix Ulrich
Greenhorn

Joined: Jun 11, 2001
Posts: 9
Thanks Dave - that's kind of what I've been trying:
InputStream is = ClassLoader.getSystemClassLoader().getSystemResourceAsStream("/db.conf");
I've also tried just getResourceAsStream(), but the input stream returned is null, and I know for sure that the file has stuff in it and that it is in the root of the classpath.
Felix =(
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
I am having the same problem. Can anyone answer? :roll:
Thanks
Geoffrey


Sun Certified Programmer for the Java 2 Platform
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: getting data from files in your CLASSPATH