1、创建文件夹。
mkdir();和mkdirs();
1 File file2 = new File("e:\demo\aa\bb\cc\dd"); 2 file2.mkdirs();//多层 3 4 5 6 for(int i = 1;i<=10;i++){ 7 8 File file = new File("e:\demo\demo"+i); 9 file.mkdir(); 10 for(int j = 0;j<=10;j++){ 11 File file1 = new File(file,"\demo"+j+".txt"); 12 file1.createNewFile(); 13 } 14 }
2、获取目录下所有的文件名与文件夹名
1 File file = new File("e:\"); 2 String [] s = file.list(); 3 System.out.println(Arrays.toString(s)); 4 for (String string : s) { 5 System.out.println(string); 6 }