Link to home
Start Free TrialLog in
Avatar of Dazza051197
Dazza051197

asked on

Returning path to class file

I want to be able to read a text file from the same directory where my Jar file resides, or class files if I've not yet packaged them up.

How do I return the path to the class file or JAR file if the class I'm in is inside a JAR file ?

Thanks
Dazza
Avatar of jerch
jerch

You can use System.getProperty("user.dir") to get the current directory where your Java program is running on.

Jerson
ASKER CERTIFIED SOLUTION
Avatar of Igor Bazarny
Igor Bazarny
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes Dazza

Use getResourceAsStream("FileName");


Shyam
Avatar of Dazza051197

ASKER

Thanks Igor

With a little bit of tweaking to the code you gave me, it now works.  The code you gave me works fine for when the code is running from the Jar file, but if I'm still in Forte it returns null, so I managed to add some code to the else of the findExtRoot() to return the filepath if it's not running from the Jar file.

Thanks
Dazza