import java.io.File;
public class ReadFile {
public static void main(String[] args) {
// path是指定目录的绝对路径
String path = "/Users/tonychan/Workspaces/MyEclipse 2017 CI/Zhangjiajie/WebRoot/pics";
getFile(path);
}
// 给定目录的绝对路径,获取该目录下的所有文件(子目录的文件也可递归得到)
public static void getFile(String path) {
// File对象 可以是文件或者目录
File file = new File(path);
File[] array = file.listFiles();
for (int i = 0; i < array.length; i++) {
if (array[i].isFile()) {
// only take file name
System.out.println("^^^^^" + array[i].getName());
// take file path and name
System.out.println("#####" + array[i]);
// take file path and name
System.out.println("*****" + array[i].getPath());
} else if (array[i].isDirectory()) {
getFile(array[i].getPath());
}
}
}
}