Class location

Hello all, hope you all having a wonderful evening. I'm trying to load my properties page from the same location as my source code. Firstly I'm doing this manually at the moment but would like to find a dynamic way of pointing to the property file. This is what I have so far:

String userHomeDir = System.getProperty("user.dir",".");

System.out.println("userHomeDir:"+userHomeDir);

String userFileDir = userHomeDir+"\\src\\my\\app\\db";

System.out.println("userFileDir"+userFileDir);

What I would like to do know is point automatically to the file location which won't be in the src file but rather were the build is going to be. Is there any way to do this because I can't see anything in theSystem.getProperty() method.

[897 byte] By [tarmenela] at [2007-10-3 10:39:17]
# 1
this.getClass().getResourceAsStream(your_file_name) will look for the file in the same directory than that of the .class file, if that is what you meant.
karma-9a at 2007-7-15 6:03:23 > top of Java-index,Java Essentials,Java Programming...
# 2
The proper place to put "resource" files is with the .class files, not with the source. Most IDEs will copy them from source to class directories.Use getClass().getResource() or getClass().getResourceAsStream() to access such data.
malcolmmca at 2007-7-15 6:03:23 > top of Java-index,Java Essentials,Java Programming...
# 3
Hi,You probably want to take a look at ClassLoader.getResourceAsStream. That's one way to load a resource (like a property file) that you have on the classpath.Kaj
kajbja at 2007-7-15 6:03:23 > top of Java-index,Java Essentials,Java Programming...
# 4
Worked like a charm but I see that unless I built the program it threw a NullPointerException. Does the method only pick up files found in the class directory?
tarmenela at 2007-7-15 6:03:23 > top of Java-index,Java Essentials,Java Programming...
# 5

> Worked like a charm but I see that unless I built the

> program it threw a NullPointerException. Does the

> method only pick up files found in the class

> directory?

not just in the class directory, no ( I assume you mean the directories where your classes compile to), but the classpath, which includes, but is not limited to, the class directory

providing I understood you right about class directory

georgemca at 2007-7-15 6:03:23 > top of Java-index,Java Essentials,Java Programming...