I want to create a folder at a particular path (location which is given by user) using java code.
File dir = new File("Hermatic");
dir.mkdir();
This code create 'hermatic' folder but i want to set path so that folder create at given location.
I want to create a folder at a particular path (location which is given by user) using java code.
File dir = new File("Hermatic");
dir.mkdir();
This code create 'hermatic' folder but i want to set path so that folder create at given location.
Is this what you are looking for?
public class Main {
public static void createFolder(String path) throws Exception {
File dir = new File(path);
dir.mkdir();
}
public static void main(String[] args) throws Exception {
String path = args[0]; //takes the first argument from the command line
createFolder(path);
}
}
So running your application with
java -jar myapp.jar /home/me/folder
would create the folder with the path /home/me/folder
String location = "C:\\user\\Desktop\\dir1\\dir2\\";
File file = new File(location + "filename.txt");