How to create a folder in Java?
With Java 7 and newer you can use the static Files.createDirectory() method of the java.nio.file.Files
class along with Paths.get
.
Files.createDirectory(Paths.get("/path/to/folder"));
The method Files.createDirectories() also creates parent directories if these do not exist.
File f = new File("C:\\TEST");
try{
if(f.mkdir()) {
System.out.println("Directory Created");
} else {
System.out.println("Directory is not created");
}
} catch(Exception e){
e.printStackTrace();
}
Call File.mkdir
, like this:
new File(path).mkdir();