import java.io.File; public class TestAllFile{ // 打印指定目录下的所有文件路径和文件名 public static void f(String dir){ try{ File f = new File(dir); String[] fileList = null; if(f.isDirectory()){ fileList = f.list(); for(int i=0; i<fileList.length; i++){ f(dir + "//" + fileList[i]); } }else{ System.out.println(dir); } }catch(Exception e){ } } public static void main (String[] args) { String s = "E:"; f(s); } }