Hi,
I would like to know what is the current directory of my class,
I have tried System.getProperty("user.dir");
but it just gives me the current directory of the application, and I
want to know the current location of a class inside a package:
Main.class.getLocation ??????????
thanks
Marcelo
Andrew Thompson - 30 Sep 2005 15:03 GMT
> I would like to know what is the current directory of my class,
Well heck.. Are you participating in this group (reading it)
or just using it as a help desk?
<http://groups.google.com/group/comp.lang.java.programmer/browse_thread/thread/04
a60fdc986505a3/7296d90d9f0c992f?lnk=raot#7296d90d9f0c992f>
<http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/3cf1e
8a4708db69c/97e364eb3bf60cba?tvc=1#97e364eb3bf60cba>
Thomas Fritsch - 30 Sep 2005 15:12 GMT
> I would like to know what is the current directory of my class,
>
[quoted text clipped - 3 lines]
>
> Main.class.getLocation ??????????
Class c = Main.class;
String s = '/' + c.getName().replace('.', '/') + ".class";
URL url = c.getResource(s);
System.out.println(url);

Signature
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
Tor Iver Wilhelmsen - 30 Sep 2005 17:19 GMT
> Class c = Main.class;
> String s = '/' + c.getName().replace('.', '/') + ".class";
> URL url = c.getResource(s);
You can shorten that to
URL url = Main.class.getResource("Main.class");
Roedy Green - 30 Sep 2005 21:31 GMT
>want to know the current location of a class inside a package:
see http://mindprod.com/jgloss/classpath.html#WHERE

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.