1 package Io; 2 3 import java.io.File; 4 import java.io.FileFilter; 5 6 public class TestFile04 { 7 public static void main(String[] args) { 8 new TestFile04().run(); 9 } 10 11 public void run() { 12 File f = new File("G:\BaiduYunDownload"); 13 File[] files = f.listFiles(new DirFilter()); 14 for (File file : files) { 15 System.out.println(file.getName()); 16 } 17 } 18 19 // 文件夹过滤器 20 class DirFilter implements FileFilter { 21 22 @Override 23 public boolean accept(File pathname) { 24 if (pathname.isDirectory()) 25 return true; 26 else 27 return false; 28 } 29 } 30 }