Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2005

Tip: Looking for answers? Try searching our database.

current directory of the class

Thread view: 
Marcelo - 30 Sep 2005 14:53 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.