Example usage for java.io File lastModified

List of usage examples for java.io File lastModified

Introduction

In this page you can find the example usage for java.io File lastModified.

Prototype

public long lastModified() 

Source Link

Document

Returns the time that the file denoted by this abstract pathname was last modified.

Usage

From source file:brut.util.BrutIO.java

public static long recursiveModifiedTime(File file) {
    long modified = file.lastModified();
    if (file.isDirectory()) {
        File[] subfiles = file.listFiles();
        for (int i = 0; i < subfiles.length; i++) {
            long submodified = recursiveModifiedTime(subfiles[i]);
            if (submodified > modified) {
                modified = submodified;//from   w w w .ja  va  2s  .  c om
            }
        }
    }
    return modified;
}

From source file:Main.java

public static boolean deleteFileByIntervalTime(File file, long intervalTime) {
    long time = System.currentTimeMillis();
    if (time - file.lastModified() > intervalTime) {
        file.delete();//from  ww  w  .java2s.co m
    }
    return true;
}

From source file:Main.java

public static File getFileForCrypt(String hash, Context context) {
    File externalCacheDir = new File(
            new File(new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data"),
                    context.getPackageName()),
            "cypher");
    externalCacheDir.mkdirs();/* w  w w. jav a  2s . c om*/

    // clear old items
    String[] files = externalCacheDir.list();
    long th = new Date().getTime() - 24 * 60 * 60 * 1000; // expire one day
    for (int i = 0; i < files.length; i++) {
        File tmp = new File(externalCacheDir, files[i]);
        if (tmp.lastModified() < th) {
            tmp.delete();
        }
    }

    // add new file
    File dst = new File(externalCacheDir, hash + ".tmp");
    if (dst.exists()) {
        dst.delete();
    }
    //      dst.deleteOnExit();
    return dst;
}

From source file:Main.java

private static boolean clearFile(File file, long date, int day) {
    if ((file != null) && (file.exists()) && (file.isFile())
            && ((date - file.lastModified()) / 86400000L > day)) {
        return file.delete();
    }/*w w w . j  ava  2s .  c  om*/
    return false;
}

From source file:Main.java

private static Map<Long, String> getFilePathAndModyTime(File file) {
    Map<Long, String> map = new HashMap<Long, String>();
    if (file.isFile()) {
        map.put(file.lastModified(), file.getAbsolutePath());
    } else if (file.isDirectory()) {
        for (File f : file.listFiles()) {
            map.putAll(getFilePathAndModyTime(f));
        }/*from   w  w  w . ja  v  a 2s .c  om*/
    }
    return map;
}

From source file:de.uni.bremen.monty.moco.CompileFilesBaseTest.java

protected static File getLastModifiedMontyFile(String folderPath) throws URISyntaxException {

    final File[] montyFilesInDir = getFiles4Filter(folderPath, new String[] { "monty", "ignore" })
            .toArray(new File[0]);
    File latestModifiedMontyProgram = montyFilesInDir[0];

    for (File file : montyFilesInDir) {
        if (file.lastModified() > latestModifiedMontyProgram.lastModified()) {
            latestModifiedMontyProgram = file;
        }/* www . j  ava 2s .  com*/
    }

    return latestModifiedMontyProgram;
}

From source file:Main.java

static public long getSettingsParmSaveDate(Context c, String dir, String fn) {
    File lf = new File(dir + "/" + fn);
    long result = 0;
    if (lf.exists()) {
        result = lf.lastModified();
    } else {//from   ww w  .  j a v a  2  s. c o m
        result = -1;
    }
    return result;
}

From source file:Main.java

public static boolean isFileExpired(final File file, final long expiredTime) {
    Date date = new Date();
    if (file.exists()) {
        return (date.getTime() - file.lastModified()) > expiredTime;
    }//from w  w w  .j  a  va2s .  com
    return false;
}

From source file:de.betterform.cache.CacheManager.java

/**
 *
 * @param file cache key/*from w  w w. j  a v  a 2s.  co  m*/
 * @param  object W3C DOM Docuemt (Cache value)
 */
public static void putIntoFileCache(File file, Object object) {
    xfFileCache.put(new Element(file.getAbsolutePath() + file.lastModified(), object));
}

From source file:Main.java

public static boolean updateFile(String path, String filename) {
    File f = new File(path, filename);
    Log.e("x", f.getAbsolutePath());
    Log.e("x", "" + f.exists());
    long fileTime = f.lastModified();
    long curTime = System.currentTimeMillis();
    long fileAge = curTime - fileTime;

    Log.d("updateFile", "fileTime: " + fileTime);
    Log.d("updateFile", "curTime: " + curTime);
    Log.d("updateFile", "fileage: " + fileAge);

    // return true if file is older than an hour
    return fileAge > (1000 * 60 * 60);

}