遍歷c盤下的所有檔案和資料夾
阿新 • • 發佈:2021-02-05
package com.dd2; import java.io.File; public class T1 { public static void main(String[] args) { File file = new File("C://QMDownload"); pp(file); } private static void pp(File file) { if (file != null) { if (file.isFile()) { System.out.println("檔案--" + file.getAbsolutePath()); } else if (file.isDirectory()) { System.out.println("資料夾--" + file.getAbsolutePath()); File[] arr = file.listFiles(); if (arr!= null && arr.length > 0) { for (File temp : arr) { pp(temp); } } } } } }