import java.io.File;public class FileListTest { public void tree(File file){ if(file.listFiles()!=null)//当目录File所代表的目录下存在文件时执行递归操作 { File[] list = file.listFiles(); for(File test : list) { if(test.isDirectory()) { tree(new File(test.getAbsolutePath()+"\\"));//为目录File时进行递归 } System.out.print(test.getAbsolutePath()); } } } public static void main(String[] args) { File file = new File("E:\\"); FileListTest test = new FileListTest(); test.tree(file); }}