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!
~is not going to be expanded by most (any?) Java APIs.~is resolved by the shell (e.g. Bash). You'll need to use/home/xyz/test.