import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class ReadFile {
/*
* 读取指定路径下的文件名和目录名
*/
public List<String> getFileList(String directoryName) {
File file = new File(directoryName);
List<String> a = new ArrayList<>();
File[] fileList = file.listFiles();
for (int i = 0; i < fileList.length; i++) {
if (fileList[i].isFile()) {
String fileName = fileList[i].getName();
a.add(directoryName + fileName);
System.out.println("文件:" + fileName);
}
if (fileList[i].isDirectory()) {
String fileName = fileList[i].getName();
System.out.println("目录:" + fileName);
}
}
return a;
}
public static void main(String[] args) {
ReadFile rf = new ReadFile();
// rf.getFileList();
}
}