Java 实例 - 查看主机指定文件的最后修改时间
以下实例演示了如何查看主机指定文件的最后修改时间:
Main.java 文件
importjava.net.URL;
importjava.net.URLConnection;
importjava.util.Date;
importjava.text.SimpleDateFormat;
publicclassMain{publicstaticvoidmain(String[]argv)throwsException{URLu = newURL("http://127.0.0.1/test/test.html");
URLConnectionuc = u.openConnection();
SimpleDateFormatft = newSimpleDateFormat("yyyy-MM-dd hh:mm:ss");
uc.setUseCaches(false);
longtimestamp = uc.getLastModified();
System.out.println("test.html 文件最后修改时间 :" + ft.format(newDate(timestamp)));
}}
以上代码运行输出结果为:
test.html 文件最后修改时间 :2018年09月06日 10:06:04