算法 第四版 1.3.43 文件列表

xiaoxiao2021-02-28  17

package Cap1; import java.io.File; import edu.princeton.cs.introcs.StdOut; public class MyListFiles { /** * @param args */ public static void listAllFiles(String path, int dep){ File f = new File(path); File[] list = f.listFiles(); for(File newFile:list){ for(int i=0;i<dep;i++) StdOut.print("\t"); StdOut.println(newFile.getName()); if(newFile.isDirectory()){ listAllFiles(newFile.getAbsolutePath(), dep+1); } } return; } public static void main(String[] args) { // TODO Auto-generated method stub String path = "C:\\Users\\O_o\\Desktop\\TestFile"; StdOut.println(path); listAllFiles(path, 0); } }

C:\Users\O_o\Desktop\TestFile Dir1 File1.1 File1.2 Dir2 File2.1 File2.2 File2.3 File1 File2

转载请注明原文地址: https://www.6miu.com/read-200094.html

最新回复(0)