How can you create a directory anywhere on your hard drive using Java? For Example, I would like to create a folder in the home folder of the computer. If I use this code:
File file = new File("~/test");
if (!file.exists()) {
try {
folder.mkdirs();
} catch(Exception e) {
JOptionPane.showMessageDialog(null, "There was an error: \n"+e, "Error!", 1);
}
}
it creates a folder name “~” and a folder inside that named “test” in the directory my project is in.
How can i get Java to create the folder in my home folder?
Thanks!
You can get the user directory path by getting the system property “user.home”