java--mkdirs()

import java.io.*;
import java.nio.file.Files;
import java.util.*;
import java.util.regex.*;
public class test {
    public static void main(String[] args) throws IOException{
        File oldfile = new File("C:\Users\15773\Desktop\test\1.txt");
        File newfile = new File("C:\Users\15773\Desktop\test2");
        //类似于python的basename,获取文件名
        System.out.println("文件的名字是  "+oldfile.getName());
        //判断文件路径是否存在
        if (! newfile.exists()){
            System.out.println("路径不存在,开始新建");
            //此函数用于新建路径
            newfile.mkdirs();
            System.out.println("新建成功");
        }else{
            System.out.println("路径已经存在了");
        }
    }
}
原文地址:https://www.cnblogs.com/shunguo/p/14496737.html