java 获取路径下所有文件

思路:通过递归遍历文件夹

	public static void getFiles(List<File>fileList, String path){
		try {
			File file = new File(path);
			if(file.isDirectory()){
				File []files = file.listFiles();
				for(File fileIndex:files){
					//如果这个文件是目录,则进行递归搜索
					if(fileIndex.isDirectory()){
						getFiles(fileList,fileIndex.getPath());
					}else {
						//如果文件是普通文件,则将文件句柄放入集合中
						fileList.add(fileIndex);
					}
				}
			}
		}catch (Exception e){

		}
	}

猜你喜欢

转载自blog.csdn.net/rumengqiang/article/details/80480597