public void loadFilenames(String path) {
File file = new File(path);
File[] filesName = file.listFiles();
//包含路径
for (int i = 0; i < filesName.length; i ) {
if (filesName[i].isFile()) {
//路径
System.out.println(filesName[i]);
} else if (filesName[i].isDirectory()) {
System.out.println(filesName[i]);
}
}
System.out.println("---------------------");
//只有文件名称
for (int i = 0; i < filesName.length; i ) {
if (filesName[i].isFile()) {
//路径
System.out.println(filesName[i].getName());
} else if (filesName[i].isDirectory()) {
System.out.println(filesName[i].getName());
}
}
System.out.println("---------------------");
//包含路径
for (int i = 0; i < filesName.length; i ) {
if (filesName[i].isFile()) {
//路径
System.out.println(filesName[i].getPath());
} else if (filesName[i].isDirectory()) {
System.out.println(filesName[i].getPath());
}
}
}