You can create new folders in java by implementing the File class. First you have to specify the path under which the folder should be created. If there is no folder with the given name, it will be created with the mkdir() function. If the folder already exists under the given path, an error message is displayed.
import java.io.File;
public class CreateDirectory {
public static void main(String[] args) {
File dir = new File("/path/directory-name");
if (!dir.exists()) {
System.out.println("Directory created successfully");
dir.mkdir();
} else {
System.out.println("Directory creation failed");
}
}
}
Directory created successfully