Java如何获取一个文件的修改时间?

解决方案 »

  1.   

    lastModified()这个函数可以获取,获取的时间是1142587459093,1142587459093不知道是什么意思?
      

  2.   

    lastModifiedpublic 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
    ---------------------------------------------------------------------------------------
    看java docs很有帮助的,建议你常翻翻看。
      

  3.   

    剩下的部分,就看你如何使用Calendar这个类了。
      

  4.   

    LZ真lazy!
    --不过我也不熟悉这个类,嘿。
      

  5.   

    哎,不是lazy啊,是不会啊,
     Calendar c = Calendar.getInstance();
     Date date = c.getTime();
     System.out.println(date.toLocaleString());
     这个可以得到 2006-3-29 16:10:36
    但是lastModified()所获取的时间应该怎么转啊
      

  6.   

    import java.util.*;
    import java.io.*;
    public class test{
    public static void main(String[] args){
    File f=new File("test.txt");
    long time=f.lastModified();
    Calendar cal=Calendar.getInstance();
    cal.setTimeInMillis(time);
    System.out.println(cal.getTime().toLocaleString());
    }
    }