file 类
![](java File类/1648477074671.png)
![](java File类/1648477093771.png)
![](java File类/1648477110795.png)
![](java File类/1648477118325.png)
文件和文件夹的创建删除等
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| public class FileMethodDemo2 { public static void main(String[] args) throws IOException { File file = new File("e:\\file.txt"); boolean b1 = file.createNewFile(); System.out.println("b1=" + b1); boolean b2 = file.delete(); System.out.println("b2="+b2);
boolean b3 = file.exists(); System.out.println("b3="+b3); File dir = new File("e:\\abc"); boolean b4 = dir.mkdir(); System.out.println("b4="+b4); boolean b5 = dir.delete(); System.out.println("b5=" + b5); File f = new File("e:\\javahaha"); System.out.println(f.isFile()); System.out.println(f.isDirectory()); } }
|
文件过滤器
1 2 3 4 5 6 7 8 9 10 11 12 13
| public class FileDemo2 { public static void main(String[] args) { File file = new File("E:\\code\\day11_code"); File[] files = file.listFiles(new MyFileFilter()); for (File f : files) { System.out.println(f); } } }
|
1 2 3 4 5 6
| class MyFileFilter implements FilenameFilter{ public boolean accept(File dir, String name) { return name.endsWith(".java"); } }
|