Easy Tutorial
❮ Arrays Insert Java String Hashcode ❯

Java Example - View the Last Modified Time of a Specified File on the Host

Java Examples

The following example demonstrates how to view the last modified time of a specified file on the host:

Main.java File

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 file last modified time :" + ft.format(new Date(timestamp)));
    }
}

The output of the above code is:

test.html file last modified time :2018-09-06 10:06:04

Java Examples

❮ Arrays Insert Java String Hashcode ❯