Finding JAR location
I have a problem whereby if I open my jar file from the start menu, it fails to find the xml file I want it to read that is in the same directory. But if I open the folder they are both in, then open teh jar it works fine. Is there any way I can find the location of the jar file, ie C:\Documents and Settings\etc on windows, and then use that to open the file?
# 2
Sorry, the question was a bit obscure. It's a problem with windows, whereby if you open run a jar file like you would a shortcut in the start menu, it changes the working directory to not the start menu. I found this solution with some help though:
// Finds the location of a file inside the jar, then cuts it down
// to find the location of the XML file
String address = this.getClass().getResource("[file name]").toString();
address = address.substring(10, (address.length() - 26)) + "[file name]";
// Read the file one character at a time, adding them to a String
FileReader in = new FileReader(address.replace("%20", " "));
Not pretty but works, unless you change the jar name...but I'm working on that