Hi:
Is there an equivalent form of getCodeBase() I can use in an application to find the directory the application is running from?
Thanks,
Derek
Printable View
Hi:
Is there an equivalent form of getCodeBase() I can use in an application to find the directory the application is running from?
Thanks,
Derek
Try
public static Properties getProperties().
It should provide you with a set of properties consisting of for example:
java.version
java.vendor
java.home (java installation directory)
java.class.path (could come in handy for you)
os.name
os.version
user.name (user account name!)
user.home (user's home directory)
user.dir (user's current working directory.
Probably what you're looking for)
Yep, there's a way:
String classDirectory = getClass().getResource("ClassName.class").toString();
This line of code gives you the string representation of the directory where the class is.
Hope that helps.
Matty
When I use the following:
t = new Test();
String classDirectory = t.getClass().getResource("Test.class").toString();
I get 'systemresource:/FILE0/+/com/xxx/yyy/Test.class' (without the quotes) ? What does /FILE0/+/ mean ? I was expecting drive and directory info (Window NT)?
One simple solution is :
public String getClassDirectory() throws IOException {
File f = new File(".");
return f.getCanonicalPath();
}