public void getFiles(String filePath){
File root = new File(filePath);
File[] files = root.listFiles();
for(File file:files){
if(file.isDirectory()){
getFiles(file.getAbsolutePath());
//filelist.add(file.getAbsolutePath());
System.out.println("显示"+filePath+"下所有子目录"+file.getAbsolutePath());
}else{
System.out.println("显示"+filePath+"下所有子目录及其文件"+file.getAbsolutePath());
}
}
}
获取路径后面的文件名称:
String newFilePath = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf("\\")+1);