Here you can find the source of isNewer(File file, File reference)
File
is newer than the reference File
.
Parameter | Description |
---|---|
file | the <code>File</code> of which the modification date must be compared |
reference | the <code>File</code> of which the modification date is used |
true
if the File
exists and has been modified more recently than the reference File
.
public static boolean isNewer(File file, File reference)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { /**/*ww w. j a v a2 s. c om*/ * PerformTest if specified <code>File</code> is newer than the reference <code>File</code>. * * @param file the <code>File</code> of which the modification date must be compared * @param reference the <code>File</code> of which the modification date is used * @return <code>true</code> if the <code>File</code> exists and has been modified more * recently than the reference <code>File</code>. */ public static boolean isNewer(File file, File reference) { if (reference.exists() == false) { throw new IllegalArgumentException("The reference file '" + file + "' doesn't exist"); } return isNewer(file, reference.lastModified()); } /** * Tests if the specified <code>File</code> is newer than the specified time reference. * * @param file the <code>File</code> of which the modification date must be compared. * @param timeMillis the time reference measured in milliseconds since the * epoch (00:00:00 GMT, January 1, 1970) * @return <code>true</code> if the <code>File</code> exists and has been modified after * the given time reference. */ public static boolean isNewer(File file, long timeMillis) { if (!file.exists()) { return false; } return file.lastModified() > timeMillis; } public static boolean isNewer(String file, long timeMillis) { return isNewer(new File(file), timeMillis); } public static boolean isNewer(String file, String reference) { return isNewer(new File(file), new File(reference)); } }