My problem is, I have a file, in a folder called res. now in that folder i have my application.properties file.
my program is running from a executable jar file, and that res folder IS NOT packaged in the jar(if it was i wouldnt be able to save the application.properties file.
how do i get the location of that folder, that is outside of the jar, and then if it doesnt exist, create it?
ive tried getClass().getClassLoader().getResource(""); but my program still throws up an error when its in jarmode...
heres my code if it helps
xstream is just a xml parser
Properties.class holds my variables
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| private void load(){ xstream = new XStream(); xstream.alias("properties", Properties.class); URL propURL = null; propURL = getClass().getClassLoader().getResource("res/application.properties"); System.out.println(propURL); String xml = "";
try{ File f = new File(propURL.toURI()); BufferedReader inProp = new BufferedReader(new FileReader(f)); String m = ""; System.out.println("Reading..."); prop = (Properties)xstream.fromXML(inProp); System.out.println("Read"); inProp.close(); }catch(Exception e){ if(e.getMessage() == null){ JOptionPane.showMessageDialog(null, "Application is corrupted, reinstall"); System.exit(0);
} e.printStackTrace(); } lastDir = new File(prop.getLastLoadFolder()); urlLink.setText(prop.getLastUrl()); } |