Reputation: 664
I want to do that:
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir" + "\\datos_medidas")));
But I recieve a NullPointerException.
All I want to do is to put the current directory path on a folder that is in the user.dir folder, I have a folder in user.dir and I want to save my files in that folder, but I don't know how to do it.
I can't use a "literal path" I need a relative path because this application is going to work on all windows versions and I can't use literal paths.
Upvotes: 0
Views: 829
Reputation: 115328
I think that the reason is pretty obvious. Examine your code:
System.getProperty("user.dir" + "\\datos_medidas")
You try to retrieve system property that does not exist. Instead you should retrieve system property user.dir
that represents the file system path and create File
object that uses this path as a parent:
new File(System.getProperty("user.dir"), "datos_medidas"))
Upvotes: 1