• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to find the executing directory of my class?  RSS feed

 
Hemant Agarwal
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
How to find at runtime in which directory my class is running?
 
Sarath PS
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to find:
a) the location the class was executed from
b) the classpath location from which the qualified class can be found
c) the physical location of the class file?

The previous answer will give you a)
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sarath PS:


That's not strictly platform-independent, is it? Not all O/S have "." as the current directory. Maybe it's good enough for most people these days: it does work in Windows, Unix/Linux and Mac OS X (but not older Mac OS).

I thought System.getProperty("user.dir") was the official way to do this. Is that wrong?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you need a working directory where you would like to save files, then Peter's suggestion to use System.getProperty("user.dir") should work. However, as David pointed out, your question could be taken several different ways. Can you please clarify what you are trying to do here?

Layne
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!