List of usage examples for java.io File lastModified
public long lastModified()
From source file:org.transitime.gtfs.GtfsUpdatedModule.java
/** * Copies the specified file to a directory at the same directory level but * with the directory name that is the last modified date of the file (e.g. * 03-28-2015)./* ww w . j a v a 2 s.co m*/ * * @param fullFileName * The full name of the file to be copied */ private static void archive(String fullFileName) { // Determine name of directory to archive file into. Use date of // lastModified time of file e.g. MM-dd-yyyy. File file = new File(fullFileName); Date lastModified = new Date(file.lastModified()); String dirName = Time.dateStr(lastModified); // Copy the file to the sibling directory with the name that is the // last modified date (e.g. 03-28-2015) Path source = Paths.get(fullFileName); Path target = source.getParent().getParent().resolve(dirName).resolve(source.getFileName()); logger.info("Archiving file {} to {}", source.toString(), target.toString()); try { // Create the directory where file is to go String fullDirName = target.getParent().toString(); new File(fullDirName).mkdir(); // Copy the file to the directory Files.copy(source, target, StandardCopyOption.COPY_ATTRIBUTES); } catch (IOException e) { logger.error("Was not able to archive GTFS file {} to {}", source.toString(), target); } }
From source file:com.jfinal.ext.plugin.config.ConfigKit.java
private static void checkFileModify() { Set<String> filenames = lastmodifies.keySet(); for (String filename : filenames) { File file = new File(filename); if (lastmodifies.get(filename) != file.lastModified()) { LOG.info(filename + " changed, reload."); init(includeResources, excludeResources, reload); }/*from w w w. ja v a 2s .c om*/ } }
From source file:com.scanvine.android.util.SVDownloadManager.java
public static void DeleteOldCacheFiles(Context context) { try {/*from ww w . j av a2 s. c om*/ File cacheDir = context.getCacheDir(); for (File file : cacheDir.listFiles()) { if (System.currentTimeMillis() - file.lastModified() > 1000 * 60 * 60 * 24 * 7) { Log.i("SVDownloadManager", "Deleting old cache file " + file); file.delete(); } } } catch (Exception ex) { Log.e("SVDownloadManager", "Error deleting old cache files"); } }
From source file:Main.java
public static long getFirstInstalled() { long firstInstalled = 0; PackageManager pm = myApp.getPackageManager(); try {/* www. j av a2 s . c o m*/ PackageInfo pi = pm.getPackageInfo(myApp.getApplicationContext().getPackageName(), pm.GET_SIGNATURES); try { try { //noinspection AndroidLintNewApi firstInstalled = pi.firstInstallTime; } catch (NoSuchFieldError e) { } } catch (Exception ee) { } if (firstInstalled == 0) { // old versions of Android don't have firstInstallTime in PackageInfo File dir; try { dir = new File( getApp().getApplicationContext().getExternalCacheDir().getAbsolutePath() + "/.config"); } catch (Exception e) { dir = null; } if (dir != null && (dir.exists() || dir.mkdirs())) { File fTimeStamp = new File(dir.getAbsolutePath() + "/.myconfig"); if (fTimeStamp.exists()) { firstInstalled = fTimeStamp.lastModified(); } else { // create this file - to make it slightly more confusing, write the signature there OutputStream out; try { out = new FileOutputStream(fTimeStamp); out.write(pi.signatures[0].toByteArray()); out.flush(); out.close(); } catch (Exception e) { } } } } } catch (PackageManager.NameNotFoundException e) { } return firstInstalled; }
From source file:com.ccoe.build.core.utils.FileUtils.java
public static void diskClean(File targetFolder, int retensionDays) { File[] doneFiles = loadDoneFiles(targetFolder); List<File> filesToDelete = new ArrayList<File>(); if (doneFiles == null) { System.out.println("No .done files found in folder: " + targetFolder); return;//from w ww. ja v a2 s . c o m } for (File file : doneFiles) { long diff = System.currentTimeMillis() - file.lastModified(); long interval = retensionDays * 24 * 60 * 60 * 1000; if (diff > interval) { filesToDelete.add(file); } } System.out.println("[INFO] Cleaning up " + filesToDelete.size() + " DONE files older than " + retensionDays + " days in target folder: " + targetFolder); for (File file : filesToDelete) { tryHardToDelete(file); } }
From source file:FileTableHTML.java
public static String makeHTMLTable(String dirname) { // Look up the contents of the directory File dir = new File(dirname); String[] entries = dir.list(); // Set up an output stream we can print the table to. // This is easier than concatenating strings all the time. StringWriter sout = new StringWriter(); PrintWriter out = new PrintWriter(sout); // Print the directory name as the page title out.println("<H1>" + dirname + "</H1>"); // Print an "up" link, unless we're already at the root String parent = dir.getParent(); if ((parent != null) && (parent.length() > 0)) out.println("<A HREF=\"" + parent + "\">Up to parent directory</A><P>"); // Print out the table out.print("<TABLE BORDER=2 WIDTH=600><TR>"); out.print("<TH>Name</TH><TH>Size</TH><TH>Modified</TH>"); out.println("<TH>Readable?</TH><TH>Writable?</TH></TR>"); for (int i = 0; i < entries.length; i++) { File f = new File(dir, entries[i]); out.println("<TR><TD>" + (f.isDirectory() ? "<a href=\"" + f + "\">" + entries[i] + "</a>" : entries[i]) + "</TD><TD>" + f.length() + "</TD><TD>" + new Date(f.lastModified()) + "</TD><TD align=center>" + (f.canRead() ? "x" : " ") + "</TD><TD align=center>" + (f.canWrite() ? "x" : " ") + "</TD></TR>"); }// ww w.j a v a 2s . c om out.println("</TABLE>"); out.close(); // Get the string of HTML from the StringWriter and return it. return sout.toString(); }
From source file:Main.java
/** * Tests if the specified <code>File</code> is older than the specified * time reference.//ww w .j a v a 2 s . co m * * @param file the <code>File</code> of which the modification date must * be compared, must not be {@code null} * @param timeMillis the time reference measured in milliseconds since the * epoch (00:00:00 GMT, January 1, 1970) * @return true if the <code>File</code> exists and has been modified before * the given time reference. * @throws IllegalArgumentException if the file is {@code null} */ public static boolean isFileOlder(File file, long timeMillis) { if (file == null) { throw new IllegalArgumentException("No specified file"); } if (!file.exists()) { return false; } return file.lastModified() < timeMillis; }
From source file:Main.java
/** * Tests if the specified <code>File</code> is newer than the specified * time reference.//w w w . j a va 2 s .com * * @param file the <code>File</code> of which the modification date must * be compared, must not be {@code null} * @param timeMillis the time reference measured in milliseconds since the * epoch (00:00:00 GMT, January 1, 1970) * @return true if the <code>File</code> exists and has been modified after * the given time reference. * @throws IllegalArgumentException if the file is {@code null} */ public static boolean isFileNewer(File file, long timeMillis) { if (file == null) { throw new IllegalArgumentException("No specified file"); } if (!file.exists()) { return false; } return file.lastModified() > timeMillis; }
From source file:org.shept.util.FileUtils.java
/** * Compare the source path and the destination path for filenames with the filePattern * e.g. *.bak, *tmp and copy these files to the destination dir if they are not present at the * destination or if they have changed (by modifactionDate) * /*from w w w.j a v a2 s. c o m*/ * @param destPath * @param sourcePath * @param filePattern * @return the number of files being copied */ public static Integer syncAdd(String sourcePath, String destPath, String filePattern) { // check for new files since the last check which need to be copied Integer number = 0; SortedMap<FileNameDate, File> destMap = fileMapByNameAndDate(destPath, filePattern); SortedMap<FileNameDate, File> sourceMap = fileMapByNameAndDate(sourcePath, filePattern); // identify the list of source files different from their destinations for (FileNameDate fk : destMap.keySet()) { sourceMap.remove(fk); } // copy the list of files from source to destination for (File file : sourceMap.values()) { log.debug(file.getName() + ": " + new Date(file.lastModified())); File copy = new File(destPath, file.getName()); try { if (!copy.exists()) { // copy to tmp file first to avoid clashes during lengthy copy action File tmp = File.createTempFile("vrs", ".tmp", copy.getParentFile()); FileCopyUtils.copy(file, tmp); if (!tmp.renameTo(copy)) { tmp.delete(); // cleanup if we fail } number++; } } catch (IOException ex) { log.error("FileCopy error for file " + file.getName(), ex); } } return number; }
From source file:com.nohowdezign.gcpmanager.Main.java
public static void dowloadFile(Job job) throws CloudPrintException { SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH-mm-ss"); File directory = new File( "./jobstorage/" + sdf.format(Long.parseLong(job.getCreateTime())) + "/" + job.getOwnerId() + "/"); if (!directory.exists()) { directory.mkdirs();/* ww w. ja v a 2 s .c o m*/ } String fileName = FilenameUtils.removeExtension(job.getTitle()) + ".pdf"; File outputFile = new File(directory, fileName); if (!outputFile.exists()) { cloudPrint.downloadFile(job.getFileUrl(), outputFile); logger.info("mod date: {}", sdf.format(outputFile.lastModified())); JobStorageManager manager = new JobStorageManager(); manager.addJobFileDownloaded(outputFile); } }