import java.io.File;
/**
* @author Mr. Zhao
* @date 2020-07-29 15:01
* 类描述:
*/
public class test1 {
private static String filePath = "";
public static Long modifyTime = (long)0;
public static void main(String[] args) {
//操作路径
File my = new File("E:\\ftp");
print(my);
System.out.println(filePath);
//输出路径
System.out.println(modifyTime);
}
//递归调用
public static void print(File file) {
//判断对象是否为空
if (file!=null) {
//如果是目录
if (file.isDirectory()) {
//列出全部文件
File f[] = file.listFiles();
//判断此目录能否列出
if (f!=null) {
for (int i = 0; i < f.length; i++) {
//因为给的路径有可能是目录,所以,继续判断
print(f[i]);
}
}
} else {
String tempfilePath = file.getAbsolutePath();
if (file.lastModified() > modifyTime) {
modifyTime = file.lastModified();
filePath = tempfilePath;
}
}
}
}
}