Java 创建带多级目录的文件

时间:2022-07-07 12:14:18
 /**
     * 
     * <p>Title: main</p>  
     * <p>Description: 创建带多级目录的文件</p>  
     * @param args
     * @throws Exception
     */
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
        File file=new File("F:/2/1.txt");
        if(!file.exists()) {
        File parentFile=file.getParentFile();
        if(!parentFile.exists()) {
        parentFile.mkdirs();
        }
        file.createNewFile();
        }
}