I have tried to set relative path in Netbeans as
String fileName=getClass().getResource("./resources/folder/abc.xml").toString().substring(6);
This works properly when i run class file but, it does'nt work for jar file, the jar file does'nt run.
It gives an Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException in main method
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MyProject().setVisible(true); //Exception on this line
}
});
}
I also used this code:
File Currentdir=new File(".");
try{
String CurrentWorkingDir=Currentdir.getCanonicalPath();
} catch(Exception e){System.out.println(e);}
File file =new File(CurrentWorkingDir+"./resources/folder/abc.xml");
but in File it gives the same Exception
if i use getCanonicalPath() in String as:
String fileName=CurrentWorkingDir+./resources/folder/abc.xml"; //CurrentWorkingDir=Currentdir.getCanonicalPath();{code}
it works properly
Is there any way to set relative path so it works in any situation.
Edited by: mohni on Aug 28, 2012 10:25 AM
Edited by: mohni on Aug 28, 2012 10:26 AM