Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to I check when a file was last modified ????  RSS feed

 
peter moss
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I cant seem to get this to work:

this is a JSP page:
-----------------------------------------------
<%@ page import="java.io.*" %>
<%
//this is the folder I am trying to get info on
//i want to find out when it was last modified
File dir = new File("/usr/local/test");
String lastmod = dir.getLastModified();
%>
------------------------------------
I get this error:
cannot resolve symbol
symbol : method getLastModified ()
location: class java.io.File
String lastmod = dir.getLastModified();
^
1 error
I also tried .doGetLastModified()
and .getLastModifiedTime();
But they dont work either.

What am I doing wrong?
thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JDK Javadocs are your friends: see here. The method you want is called "lastModified()" .
[ September 09, 2003: Message edited by: Ernest Friedman-Hill ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to I/O.
bear
 
peter moss
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is from the documentation, which is now my friend.
But I'm still struggling with how to convert that long integer of milliseconds since the last epoch into a date I can use
-------------------------
lastModified
public long lastModified()
Returns the time that the file denoted by this abstract pathname was last modified.
Returns:
A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs
------------------------
I tried taking the lastmodified output of 1063127259000 and converting it but I dont get the right date.
long i = lastmod;
long t = i * 1000000L;
java.util.Date d = new java.util.Date(t);
out.print(d);

it spits this out: Thu Sep 17 14:00:00 MDT 33691131
instead of today's date

any ideas?
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I tried taking the lastmodified output of 1063127259000 and converting it but I dont get the right date.
long i = lastmod;
long t = i * 1000000L;
java.util.Date d = new java.util.Date(t);
out.print(d);
it spits this out: Thu Sep 17 14:00:00 MDT 33691131
instead of today's date

You don't want to multiply the results by 1000000L. Simply do:
long i = lastmod;
java.util.Date d = new java.util.Date(i);
out.print(d);
or
java.util.Date d = new java.util.Date(lastmod);
out.print(d);

You should get the correct date.
[ September 09, 2003: Message edited by: Wayne L Johnson ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!