Java 实例 - 查看主机指定文件的最后修改时间

Java 教程 · 2019-02-11 21:12:06

以下实例演示了如何查看主机指定文件的最后修改时间:

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 教程 文章: https://www.codercto.com/courses/l/12.html

查看所有标签

How to Build a Billion Dollar App

How to Build a Billion Dollar App

George Berkowski / Little, Brown Book Group / 2015-4-1 / USD 24.95

Apps have changed the way we communicate, shop, play, interact and travel and their phenomenal popularity has presented possibly the biggest business opportunity in history. In How to Build a Billi......一起来看看 《How to Build a Billion Dollar App》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具