package com.companyname.common.test; import java.io.File; import java.io.IOException; /** * @author shusheng * @description * @Email shusheng@yiji.com * @date 2018/10/12 16:29 */ public class FileDemo2 { public static void main(String[] args) throws IOException { File file1 = new File("D:\test1"); System.out.println("mkdir:"+file1.mkdir()); // File file2 = new File("D:\test2\a.txt"); // System.out.println("createNewFile:"+file2.createNewFile()); /**Exception in thread "main" java.io.IOException: 系统找不到指定的路径。 at java.io.WinNTFileSystem.createFileExclusively(Native Method) at java.io.File.createNewFile(File.java:1012) at com.bornsoft.test.capitalpool.tyc.FileDemo2.main(FileDemo2.java:20)*/ /**创建多层目录(文件夹)*/ File file3 = new File("D:\test6\test2\test3\test4"); System.out.println("mkdirs:"+file3.mkdirs()); } }