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:Main.java

public static String getETag(File file) {
    return Integer.toHexString((file.getAbsolutePath() + file.lastModified() + "" + file.length()).hashCode());
}

From source file:Main.java

public static void sortFileByDate(List<File> allFileList) {
    File[] files = new File[allFileList.size()];

    for (int i = 0; i < allFileList.size(); i++) {
        files[i] = allFileList.get(i);/* w  ww  .j  av a  2s  . c o m*/
    }

    Arrays.sort(files, new Comparator<File>() {
        public int compare(File f1, File f2) {
            return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
        }
    });

    allFileList.clear();

    allFileList.addAll(Arrays.asList(files));
}

From source file:Main.java

public static String formatPhotoDate(String path) {
    File file = new File(path);
    if (file.exists()) {
        long time = file.lastModified();
        return formatPhotoDate(time);
    }//from   w w w.  j  av  a2 s.c  o m
    return "1970-01-01";
}

From source file:Main.java

public static Date getFileLastModified(String filePath) {
    File file = new File(filePath);
    if (file.exists()) {
        return new Date(file.lastModified());
    } else {/*from w ww  . ja v  a  2  s.c om*/
        return null;
    }
}

From source file:Main.java

/**
 * Get give package app install date.//w  ww .  j  a v a  2  s . c  o m
 * 
 * @param context Object of {@link Context}.
 * @param pkg Package name.
 * @return Measured in milliseconds since January 1st, 1970, midnight. Returns 0 if the file does not exist.
 */
public final static long getAppInstallDate(Context context, String pkg) {
    if (null == context || null == pkg) {
        return System.currentTimeMillis();
    }

    PackageManager pm = context.getPackageManager();
    try {
        ApplicationInfo info = pm.getApplicationInfo(pkg, 0);

        // 2.3(API level 9) ApplicationInfo have a method to get install time.
        // but we can't use it. (for support 2.2 -_-||).
        File file = new File(info.sourceDir);
        return file.lastModified();

    } catch (Exception e) {
        e.printStackTrace();
        return System.currentTimeMillis();
    }
}

From source file:Main.java

public static String getLastModifiedTime(String filePath) {
    File file = new File(filePath);
    if (file.exists()) {
        return String.valueOf(file.lastModified());
    }//w ww  .ja  v a 2s .co m
    return null;
}

From source file:Main.java

public static Date getFileDate(String lc_cmd, String lc_file) {
    Date lastModDate = null;//from  ww w . ja  va2 s.  c o m
    File file = new File(lc_file);
    if (file.exists()) {
        lastModDate = new Date(file.lastModified());
        // Log.i("File last modified @ : "+ lastModDate.toString());
    }
    return lastModDate;
}

From source file:Main.java

private static void mergeExeBatchFiles() {
    File file = new File(batchDir);
    System.out.println("debug:current path = " + file.getAbsolutePath());
    File[] files = file.listFiles();
    if (files == null || files.length == 0) {
        return;//from  ww  w.j a v  a 2s  .  c o m
    }
    Arrays.sort(files, new Comparator<File>() {
        public int compare(File file1, File file2) {
            if (file1.lastModified() > file2.lastModified()) {
                return 1;
            } else if (file1.lastModified() < file2.lastModified()) {
                return -1;
            } else {
                return 0;
            }
        }
    });
    StringBuffer command = new StringBuffer();
    for (File f : files) {
        command.append("call ").append(f.getAbsolutePath()).append("\n");
    }
    try {
        String filePath = batchDir + "build.bat";
        writeFile(filePath, command.toString());
        Runtime.getRuntime().exec("cmd /c start " + filePath);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static boolean isCacheDataFailure(Context context, String cacheFile) {
    File data = context.getFileStreamPath(cacheFile);
    return !data.exists() || (System.currentTimeMillis() - data.lastModified()) > CACHE_TIME;
}

From source file:org.pau.assetmanager.viewmodel.chart.ResourceImageGenerator.java

private static void cleanTempFolder(File directory) {
    Calendar cal = Calendar.getInstance();
    int daysBack = 1;
    cal.add(Calendar.DAY_OF_MONTH, daysBack * -1);
    long purgeTime = cal.getTimeInMillis();
    File[] files = directory.listFiles();
    for (File file : files) {
        if (file.lastModified() < purgeTime) {
            file.delete();//from w  w w.  j  a  v a 2 s .c  o m
        }
    }
}