Click to See Complete Forum and Search --> : getCodeBase() equivalent for application?
dmunoz
April 2nd, 1999, 12:17 PM
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
ANV
April 6th, 1999, 12:32 PM
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)
April 15th, 1999, 11:39 AM
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
October 8th, 1999, 04:08 PM
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)?
poochi
October 8th, 1999, 04:54 PM
One simple solution is :
public String getClassDirectory() throws IOException {
File f = new File(".");
return f.getCanonicalPath();
}
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.