import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class FindFiles {
public static void main(String[] args) {
String path="e:/service_all";
FindFilesMethod1(path);
}
public static void FindFilesMethod1(String path){
List<Map<String, Object>> files=new ArrayList<Map<String,Object>>();
List<Map<String, Object>> folders=new ArrayList<Map<String,Object>>();
File file=new File(path);
File[] tempList = file.listFiles();
System.out.println("该目录下对象个数:"+tempList.length);
for (int i = 0; i < tempList.length; i++) {
if (tempList[i].isFile()) {
Map<String,Object> filesMap=new HashMap<String, Object>();
filesMap.put("fileUrl", tempList[i].toString().replaceAll("\\\\", "/"));
filesMap.put("fileName", tempList[i].getName().toString().replaceAll("\\\\", "/"));
files.add(filesMap);
}
if (tempList[i].isDirectory()) {
Map<String,Object> foldersMap=new HashMap<String, Object>();
foldersMap.put("folderUrl", tempList[i].toString().replaceAll("\\\\", "/"));
foldersMap.put("folderName", tempList[i].getName().toString().replaceAll("\\\\", "/"));
folders.add(foldersMap);
}
}
for(Map<String, Object> realfile:files){
System.out.println("文件 路径:"+realfile.get("fileUrl")+"&文件名:"+realfile.get("fileName"));
}
for(Map<String, Object> realfolder:folders){
System.out.println("文件夹路径:"+realfolder.get("folderUrl")+"&文件夹名:"+realfolder.get("folderName"));
}
}
}