java扫描硬盘中的指定后缀文件(写着玩) ﹏ヽ暗。殇╰゛Y 2022-05-10 18:48 134阅读 0赞 package day20180914; import java.io.File; /** * 扫描硬盘 */ public class diskScan { /** * 主函数 */ public static void main(String[] args) { // 获取所有盘符 File[] listRoots = File.listRoots(); for (File disk : listRoots) { File file = new File(disk.getAbsolutePath()); getFileName(file); } } /** * 递归扫描文件 */ public static void getFileName(File file){ File[] listFiles = file.listFiles(); if(listFiles != null && listFiles.length >0){ for (File file2 : listFiles) { if(file2.isDirectory()){ getFileName(new File(file2.getAbsolutePath())); } if(file2.isFile()){ String path = file2.getAbsolutePath(); if(path.endsWith(".txt") || path.endsWith(".pdf") || path.endsWith(".doc") || path.endsWith(".docx") || path.endsWith(".ppt") || path.endsWith(".excel")){ System.out.println(file2.getAbsolutePath()); } } } } } }
还没有评论,来说两句吧...