aspose file tools*
The moose likes I/O and Streams and the fly likes Time Stamp for an external file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Time Stamp for an external file" Watch "Time Stamp for an external file" New topic
Author

Time Stamp for an external file

Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Is there a way that I can get a timestamp from a given file at a specified path. For example, how can I get a time stamp from
C:\myRoot\myTextFile.txt
and have it print out
04/11/2001 01:00:00
or something close so that we know its a time and date.
-Dale
------------------
What's this H2SO4 doing in my fridge?? ( thud )


By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Vinod Mehta
Greenhorn

Joined: Mar 13, 2001
Posts: 9
import java.io.*;
import java.util.*;
public class test {
public static void main (String args []) {
File f = new File ("C:\\Autoexec.bat");
System.out.println(f.lastModified());
Calendar c = Calendar.getInstance();
c.setTime(new Date(f.lastModified()));
String szTime = "Last Modified on " + c.get(Calendar.MONTH) + "/" + c.get(Calendar.DATE) + "/" + c.get(Calendar.YEAR) +
" At " + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND) + ":" + c.get(Calendar.MILLISECOND) + c.get(Calendar.AM_PM);
System.out.println (szTime);
}
}
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Thanks for your help! PERFECT!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Time Stamp for an external file