Java Is File Newer isNewer(String file, String reference)

Here you can find the source of isNewer(String file, String reference)

Description

is Newer

License

Open Source License

Declaration

public static boolean isNewer(String file, String reference) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    public static boolean isNewer(String file, String reference) {
        return isNewer(new File(file), new File(reference));
    }//from w w  w.j a  v  a  2 s  .c  o m

    /**
     * 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);
    }
}

Related

  1. isNewer(File file, File reference)
  2. isNewer(File file1, File file2)
  3. isNewerOrEqual(String newFile, String oldFile)