在d盘中创建⼀个⽂件夹在⽂件夹⾥创建三个txt⽂本 1import java.io.File;
2import java.io.IOException;
3
4public class FileDemo {
5public static void main(String[] args) {
6// 抛除异常IOEcxception
7try {
8            fun();
9        } catch (IOException e) {
10            e.printStackTrace();
11        }
12    }
13public static void fun() throws IOException {
14// 在d盘创建⼀个⽂件夹aaa  madir()创建⽂件夹⽬录
15        File file = new File("d:\\aaa");
16boolean mkdir = file.mkdir();
17        System.out.println(mkdir);
18// 在d盘的⽂件夹aaa⾥⾯创建三个⽂本  createNewFile()创建⽂件
19        File file1 = new File("d:\\aaa\\");
20boolean newFile1 = ateNewFile();
21        System.out.println(newFile1);
22        File file2 = new File("d:\\aaa\\");
23boolean newFile2 = ateNewFile();
24        System.out.println(newFile2);
25        File file3 = new File("d:\\aaa\\");
26boolean newFile3 = ateNewFile();
27        System.out.println(newFile3);
28
29// 多创建了⼀个⽂本
30// 删除⽂件夹内的⽂本
31        File file4 = new File("d:\\aaa\\");
32boolean delete = file4.delete();
java创建文件33        System.out.println(delete);
34
35// 遍历⽂件夹aaa内的三个⽂本  list() 遍历
36        File file5 = new File("d:\\aaa");
37        String[] list = file5.list();
38for(String i:list){
39            System.out.println(i);
40        }
41    }
42 }
打印结果再看看d盘有没有成功创建⽂件