current directory of the class

M

Marcelo

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
 
T

Thomas Fritsch

Marcelo said:
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 ??????????

Class c = Main.class;
String s = '/' + c.getName().replace('.', '/') + ".class";
URL url = c.getResource(s);
System.out.println(url);
 
T

Tor Iver Wilhelmsen

Thomas Fritsch said:
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");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top