• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need info on File.lastModified()  RSS feed

 
vineet kamdar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, this is my first post.

File oldFile = new File(list[i]);
Long modificationTime = new Long(oldFile.lastModified());

As per the javadocs lastModified() should return the time when the file was last modified. But everytime its returning "0".

Please help me out with this.

Regards,
Vineet.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is exactly rite.. just check file or create some new file then test it. It will return something like '1227690294469'..
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Try modifying the File; write something in it, then get its modification time again. Never tried it myself, but it looks as if a File which is created doesn't have a modification time. Not until you write or delete something in it.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure the file exists? lastModified returns 0 if the file does not exist or the modification time cannot be retrieved.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!