| Author |
Current Directory for Class File
|
Neil Johnson
Greenhorn
Joined: Jan 22, 2002
Posts: 11
|
|
I would like to be able to open a properties file which is kept in the same directory as the main class file (or jar) that is currently open. However, when I use the System.getProperty() method with various keys, I get back the location of the forte directory, not the location my class file is running from. I have checked the forums and the sun site, with no luck. This should be easy, please help me out. Thanks, Neil
|
 |
Zakaria Haque
Ranch Hand
Joined: Jan 02, 2002
Posts: 60
|
|
having the properties file in the same directory as the class with main does not help a lot. If you want to access the file only with its name (and not other path info) you need to keep it in the directory from where the JVM was executed. A better option is to use getResourceAsStream(String) of java.lang.Class or java.lang.ClassLoader , you can do something like //within main(String[]) of class Foo Properties prop = new Properties().load((Foo.class).getResourceAsStream("propFileName)); Hope it helps.
|
tobe bondhu nouka bherao<br />shonabo gaan aj shara raat
|
 |
Neil Johnson
Greenhorn
Joined: Jan 22, 2002
Posts: 11
|
|
Thanks, that worked! The syntax did not work exactly, but the concept worked perfectly. I appreciate you taking the time to answer, and the rest of the stuff in the Class class looks interesting as well. This will make the application a lot easier to use as well. Thanks, Neil
|
 |
 |
|
|
subject: Current Directory for Class File
|
|
|