JAR path on PDA
Hello everyone,
Anyone knows how to find the current directory a jar is located and executed on a PDA or Pocket PC?
I have tried:
File file =new File("");
System.out.println("Absolute Path: "+file.getAbsolutePath());
This seems to work just fine on a Windows Platform but when trying to execute the same JAR file from various folders(of various depth) on the PDA it always prints the root directory "\". Anyone has experienced similar issues? Anyone has an answer for this?
Thanks a lot, Chris
The mistake lies in assuming that the present working directory is the always program location. Even on Windows it might not work as soon as you use a shortcut e.g..
First, why do you need that directory? Second: add some "anchor" file to your JAR. Grab it using ClassLoader.getResource(). Parse the directory from the resulting URL.
Thanks for the reply CeciNEstPasUnProgrammeur.
I need to point my JAR file to the directory of some images i am using for the GUI (using SWT) for example:
File file = new File("");
final String path = file.getAbsolutePath()+"\\images\\";
image = new Image(null, new FileInputStream(path+"myImage.png"));
This is the code i was trying to use so far (please note that using SWT on PDA requires the FileInputStream to read an image).
My project concerns some sort of file downloader so the current working directory is also needed to point where the files are downloaded. Also, i need to load some configuration files needed by the JAR.
Could you please explain your second suggestion or perhaps point to a snippet as i didnt quite understand?
add some "anchor" file to your JAR. Grab it using ClassLoader.getResource(). Parse the directory from the resulting URL.
Thank you
Try this :-
String p = URClass.class.getResource( "URClass.class").getPath();
You'll need to massage the return path as I contains some odd stuff.
This way you dont need an anchor file, you can just use the Class you're running the code from as the anchor.
Message was edited by:
knightweb