java遍历文件
package com.vfsd.test; import java.io.File; import java.io.IOException; public class ListFileName { public static void main(String[] args) { String dir="F:\QtProject\HGD_Project_2020\"; String endName=".h"; try { listAllFile( dir, endName); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void listAllFile(String dir,String endName) throws IOException{ File dirFile = new File(dir); File[] listFiles = dirFile.listFiles(); for(int k=0;k<listFiles.length;k++) { File indexFile = listFiles[k]; if(indexFile.isFile()) { String fileName = indexFile.getName(); if(fileName.endsWith(endName)) { System.out.println(fileName); } } } } }
#######################################