Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Windows File Time stamp

807591Feb 19 2008 — edited Mar 19 2008
Hello!

From my understanding there is a File class which has several methods e.g to get file name. The problem i am having is I am trying to implement a simple program which looks at the time file stamp and output the creation, access and modified times of a file; so far I have been able to retrieve the last modified time of a file but not the access and creation times. How is this done? below there is code to retrieve last modified time:-

===================================================



package timestamp;
import java.io.*;
import java.util.*;

public class Main {


public static void main(String[] args)throws IOException {

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter file or directory name : ");

File filename = new File(in.readLine());
// check to see if its a directory
if (filename.isDirectory()){
// check to see if its a file
if (filename.exists()){

long t = filename.lastModified();
// get a directory name
System.out.println("Directory name : " + filename.getName());

System.out.println("Directory modification date and time : " + new Date(t));
}

else{
System.out.println("Directory not found!");
System.exit(0);
}
}

else{ // check to see if the file name exists
if (filename.exists()){
long t = filename.lastModified();
System.out.println("File name : " + filename.getName());
System.out.println("File modification date and time : " + new Date(t));
}
else{
System.out.println("File not found!");
System.exit(0);
}
}

}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 16 2008
Added on Feb 19 2008
6 comments
399 views