I have a java code that automatically create a file for the user after login. It works properly when I run it in netbeans/intellij. However when I compiled it into a jar file, the program works but the file is not created. Can someone please help me?
Here is my code:
private void createTxtFile(){
String loc = new File("").getAbsolutePath();
String dir = loc+"/src/lists/"+user+"-"+pass+".txt";
try {
File myObj = new File(dir);
if (myObj.createNewFile()) {
System.out.println("File created: " + myObj.getName());
}
else {
JOptionPane.showMessageDialog(this, "User already have an existing list file.");
}
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "An error occured in creating file for your list.", "Error",JOptionPane.ERROR_MESSAGE);
}
}