Java 寫道 import java.io.File; public class ListFiles { public static void main(String[] args) { File file = new File("E:" + File.separator ); getFileLists(file); } public static void getFileLists(File file) { //若是是目錄就遍歷 if (file.isDirectory()) { File f[] = file.listFiles(); if (f != null) { for (int x = 0; x < f.length; x++) { getFileLists(f[x]);//遞歸 } } } else { System.out.println(file); } } }