Get the "last modified" date from a fileTag(s): IO


Simply use the lastModified() method from a file object. but the return value is system dependent and should only be used to compare with other values returned by last modified. It should not be interpreted as an absolute time.
String s1 = "file1.dat";
String s2 = "file2.dat";

File f1 = new File(s1);
File f2 = new File(s2);

if (f1.lastModified() < f2.lastModified())
    System.out.println((s1 + " IS OLDER THAN " + S2);
To display the value of lastModified(), you need to create a Date object and then use SimpleDateFormat to get the String representation.
String  lasmod = new SimpleDateFormat("yyyy-MM-dd").format(new Date(lastmodified));

blog comments powered by Disqus