- Example - Home
- Example - Environment
- Example - Strings
- Example - Arrays
- Example - Date & Time
- Example - Methods
- Example - Files
- Example - Directories
- Example - Exceptions
- Example - Data Structure
- Example - Collections
- Example - Networking
- Example - Threading
- Example - Applets
- Example - Simple GUI
- Example - JDBC
- Example - Regular Exp
- Example - Apache PDF Box
- Example - Apache POI PPT
- Example - Apache POI Excel
- Example - Apache POI Word
- Example - OpenCV
- Example - Apache Tika
- Example - iText
- Java Useful Resources
- Java - Quick Guide
- Java - Useful Resources
How to check a file is modified at a server or not in Java
Problem Description
How to check a file is modified at a server or not?
Solution
Following example shows How to check a file is modified at a server or not.
import java.net.URL;
import java.net.URLConnection;
public class Main {
public static void main(String[] argv)throws Exception {
URL u = new URL("http://127.0.0.1/java.bmp");
URLConnection uc = u.openConnection();
uc.setUseCaches(false);
long timestamp = uc.getLastModified();
System.out.println("The last modification time of java.bmp is :"+timestamp);
}
}
Result
The above code sample will produce the following result.
The last modification time of java.bmp is :24 May 2009 12:14:50
The following is an example to check a file is modified at a server or not.
import java.net.URL;
import java.net.URLConnection;
public class Main {
public static void main(String[] argv)throws Exception {
URL u = new URL(
"https://www.tutorialspoint.com/cpp_standard_library/cpp_fstream_close.htm");
URLConnection uc = u.openConnection();
uc.setUseCaches(false);
long timestamp = uc.getLastModified();
System.out.println("The last modification time of file is :"+timestamp);
}
}
The above code sample will produce the following result.
The last modification time of file is :1479867073000
java_networking.htm
Advertisements