Compare File Dates
import java.io.File;
public class Main {
public static void main(String[] args) {
// Get the timestamp from file 1
String f1 = "run.bat";
long d1 = new File(f1).lastModified();
// Get the timestamp from file 2
String f2 = "build.xml";
long d2 = new File(f2).lastModified();
String relation;
if (d1 == d2)
relation = "the same age as";
else if (d1 < d2)
relation = "older than";
else
relation = "newer than";
System.out.println(f1 + " is " + relation + ' ' + f2);
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
IO File:
- Compare File Dates
- Compress files using with ZIP
- Concatenate files
- Copy a File with NIO FileChannel and ByteBuffer
- Copy a file with FileReader and FileWriter
- Copy a file with InputStream and OutputStream
- Copy a file and overwrite
- Delete a file
- Delete File Recursively
- Get readable file size
- Move a file
- Rename a file
- Report a file's status
- Search a file by regular expressions
- Touch a file: set File Last Modified Time