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
private void load(){
xstream = new XStream();//create the stream
xstream.alias("properties", Properties.class);
URL propURL = null;
propURL = getClass().getClassLoader().getResource("res/application.properties");//get the location(in the jar)
System.out.println(propURL);
String xml = "";
try{
File f = new File(propURL.toURI());//create file by the properties
BufferedReader inProp = new BufferedReader(new FileReader(f));
String m = "";
System.out.println("Reading...");
prop = (Properties)xstream.fromXML(inProp);//parse file into the class
System.out.println("Read");
inProp.close();
}catch(Exception e){
if(e.getMessage() == null){
JOptionPane.showMessageDialog(null, "Application is corrupted, reinstall");
System.exit(0);
//ive tried to create it here, cant figure it out
}
e.printStackTrace();
}
lastDir = new File(prop.getLastLoadFolder());
urlLink.setText(prop.getLastUrl());
}
