| Author |
Query! Reading last modified/latest file
|
ajay yaduwanshi
Greenhorn
Joined: Oct 12, 2007
Posts: 28
|
|
Hi All, I am a new bie in java, I having a very small doubt, I ant ot know how I can read the lats modified file in java. In one program I have created one file with a time stamp attached to it. say Test.txt2007-12-06 20:08:14, now in another program I want ot read the latest/last modified file. Can anybody help me how it can be done I am eagerly waiting for your reply, Please excuse me if its a very basic question Thanks & Regards Ajay Singh Yaduwanshi
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
|
|
Java uses the java.io.File class to give access to information about files such as date last modified, size, etc. - you should study the Javadocs for the File class. Bill
|
Java Resources at www.wbrogden.com
|
 |
ajay yaduwanshi
Greenhorn
Joined: Oct 12, 2007
Posts: 28
|
|
Thanks for your reply, Let me explain so that there is better understanding of the propblem I have list of files in a folder and now I want to know which of the file in the folder is latest modified, I also want to have the name of the file which last modified in the folder. I showing a small code of it which I have written for it, I am able to get the last modified value but don't know how to get the last modified file name. File f = new File("C:\\Documents and Settings\\Administrator\\Desktop\\modified"); File[] filePaths = f.listFiles(); for (int i = 0; i < filePaths.length ; i++) { long fileCreatedTime = filePaths[i].lastModified(); Thanks, Ajay
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
|
|
don't know how to get the last modified file name.
That is as simple as creating a couple of extra variables: File newestFile = null ; long newestTime = 0L; Inside the loop - every time you get a last modified time greater than newestTime store the corresponding File in newestFile and the time stamp in newestTime. At the end of the loop you are done - newestFile has the name Bill
|
 |
 |
|
|
subject: Query! Reading last modified/latest file
|
|
|