Java サンプル - ホストの指定ファイルの最終更新時刻を確認

Java 实例Java サンプル

次のサンプルは、ホストの指定ファイルの最終更新時刻を確認する方法を示しています。

Main.java ファイル

import java.net.URL; import java.net.URLConnection; import java.util.Date; import java.text.SimpleDateFormat; public class Main { public static void main(String[] argv) throws Exception { URL u = new URL("http://127.0.0.1/test/test.html"); URLConnection uc = u.openConnection(); SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss"); uc.setUseCaches(false); long timestamp = uc.getLastModified(); System.out.println("test.html ファイルの最終更新時刻 :" + ft.format(new Date(timestamp))); } }

上記のコードを実行すると、出力結果は次のようになります。

test.html 文件最后修改时间 :2018-09-06 10:06:04

Java 实例Java サンプル

その他の拡張