import java.io.*;
import java.util.ArrayList;
import java.util.List;
/**
* Created by 23232412 on 2019/7/25.
*/
public class getAllFilePaths {
public static void main(String[] args){
List<String> filePaths = new ArrayList<>();
String DirPath = "D:\\图片集\\使用数据集\\人体运动\\物流场景\\10张全";
filePaths = getAllFilePaths( DirPath, filePaths );
for ( String path : filePaths ) {
System.out.println( path );
}
}
// 递归获取某目录下的所有子目录以及子文件
private static List<String> getAllFilePaths( String filePath, List<String> filePathList ) {
File[] files = new File( filePath ).listFiles();
if ( files == null ) {
return filePathList;
}
for ( File file : files ) {
if ( file.isDirectory() ) {
// filePathList.add( file.getPath() + " <------------这是文件夹" );
getAllFilePaths( file.getAbsolutePath(), filePathList );
} else {
filePathList.add( file.getPath() );
}
}
return filePathList;
}
}
Java:获取目录下文件路径
于 2019-09-26 16:27:59 首次发布