I have written following program to get a file last modification date in java. It is very simple program. In following program I have use one class named filemodEG and using this class I have created one object to get modified date of particular file. You have to just pass this file to above object to get modified date.
Code:
import java.io.*;
import java.util.*;
public class filemodEG{
public static void main(String[] args) throws IOException{
BufferedReader ins = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter file names : ");
File filenames = new File(ins.readLine());
if (filenames.isDirectory()){
if (filenames.exists()){
long ts = filenames.lastModified();
System.out.println("Directory names : " + filenames.getName());
System.out.println("Dfile
modification date and time : " + new Date(ts));
}
else{
System.out.println("file not found!");
System.exit(0);
}
}
else{
if (filename.exists()){
long t = filename.lastModified();
System.out.println("File names : " + filenames.getName());
System.out.println("File
modification date and time is as follows : " + new Date(ts));
}
else{
System.out.println("such type of File not found!");
System.exit(0);
}
}
}
}
Bookmarks