一、单层多个
代码实现如下:
public class Main {
public static void main(String[] args) {
//在D盘中创建
File file = new File("D:"+File.separator+"docum");
file.mkdir();
//在D盘中的docum目录中创建
file = new File("D:\\docum"+ File.separator+"C");
file.mkdir();
file = new File("D:\\docum"+ File.separator+"java");
file.mkdir();
file = new File("D:\\docum"+ File.separator+"python");
file.mkdir();
}
}
二、多层单个
public class Main {
public static void main(String[] args) {
File file = new File("D:"+File.separator+"One"
+File.separator+"Two"
+File.separator+"Three");
file.mkdirs();
}
}
三、多层多个
public class Lx02 {
public static void main(String[] args) {
File file = new File("D:"+File.separator+"One"
+File.separator+"Two"
+File.separator+"Three");
file.mkdirs();
file = new File("D:\\One\\Two"+ File.separator+"a"+ File.separator+"b");
file.mkdirs();
}
}