Java Code Examples for java.io.File.lastModified()

The following are Jave code examples for showing how to use lastModified() of the java.io.File class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: oscm   File: Initializer.java   View Source Code Vote up 7 votes
/**
 * On change event
 */
void handleOnChange(File logFile) {
    try {
        long lastModif = logFile.lastModified();
        if (lastModif > logFileLastModified) {
            logFileLastModified = lastModif;
            logger.debug("Reload log4j configuration from "
                    + logFile.getAbsolutePath());
            new PropertyConfigurator().doConfigure(
                    logFile.getAbsolutePath(),
                    LogManager.getLoggerRepository());
            logFileWarning = false;
        }
    } catch (Exception e) {
        if (!logFileWarning) {
            logFileWarning = true;
            logger.error(logFile.getAbsolutePath(), e);
        }
    }
}
 
Example 2
Project: nativead   File: AbsDownloadDir.java   View Source Code Vote up 7 votes
/**
 * 检查当前目录的指定文件是否已经超过缓存时间
 *
 * @param file 待检测文件
 *
 * @return true: 超时; false:还没有超时
 */
private boolean isFileTimeOut(File file) {
	if (file == null) {
		return false;
	}
	
	if (mDirPerFileCacheTime_ms == UN_LIMT_STORE_TIME) {
		return false;
	}
	
	if (System.currentTimeMillis() - file.lastModified() > mDirPerFileCacheTime_ms) {
		return true;
	}
	
	return false;
}
 
Example 3
Project: Uranium   File: CraftOfflinePlayer.java   View Source Code Vote up 7 votes
public long getFirstPlayed() {
    Player player = getPlayer();
    if (player != null) return player.getFirstPlayed();

    net.minecraft.nbt.NBTTagCompound data = getBukkitData();

    if (data != null) {
        if (data.hasKey("firstPlayed")) {
            return data.getLong("firstPlayed");
        } else {
            File file = getDataFile();
            return file.lastModified();
        }
    } else {
        return 0;
    }
}
 
Example 4
Project: scanning   File: BundleUtils.java   View Source Code Vote up 7 votes
/**
 * Looks at installed features, gets newest uk.ac.diamond.dawn.product.feature
 * and returns that version.
 *
 * @return null if cannot find a dawn feature (might happen in debug mode)
 */
public static String getDawnVersion() {

	final File   dir = new File(getEclipseHome(), "features");
	if (!dir.exists()) return null;
	final File[] fa  = dir.listFiles();

	long date = -1;
	String version = null;
	for (File sd : fa) {
		if (!sd.isDirectory()) continue;
		Matcher matcher = FEATURE_MATCH.matcher(sd.getName());
		if (matcher.matches()) {
			if (date<sd.lastModified()) {
				date    = sd.lastModified();
				version = matcher.group(1);
			}
		}
	}
	return version;
}
 
Example 5
Project: Equella   File: Office2HtmlConversionServiceImpl.java   View Source Code Vote up 6 votes
@Override
public String convert(FileHandle itemHandle, String file, String extension) throws Exception
{
	if( disableConversion )
	{
		throw new RuntimeApplicationException("Conversion service is disabled");
	}

	ConversionFile targetHandle = new ConversionFile(itemHandle);
	String targetFile = file + '.' + extension;
	File source = fileSystemService.getExternalFile(itemHandle, file);
	File target = fileSystemService.getExternalFile(targetHandle, targetFile);

	if( !target.exists() || source.lastModified() > target.lastModified() )
	{
		LOGGER.info("Converting " + file + " to '" + extension + '\'');
		target.getParentFile().mkdirs();
		if( target.exists() )
		{
			fileSystemService.removeFile(targetHandle, targetFile);
		}

		ExecResult exec = runService(source.getAbsolutePath(), target.getAbsolutePath());
		exec.ensureOk();
	}
	else if( LOGGER.isDebugEnabled() )
	{
		LOGGER.debug("Using cached conversion " + target.getAbsolutePath());
	}

	String relativePath = PathUtils.filePath(targetHandle.getMyPathComponent(), targetFile);
	if( LOGGER.isDebugEnabled() )
	{
		LOGGER.debug("Converted path is " + relativePath);
	}

	return relativePath;
}
 
Example 6
Project: jvm-java   File: ClassFileTest.java   View Source Code Vote up 6 votes
@Before
public void compileClass() throws IOException {
    Set<File> classes = searchFile(new SuffixFilter("class"), dir);
    Map<String, File> name2file = new Hashtable<>(classes.size());
    for (File classFile : classes) {
        name2file.put(classFile.getAbsolutePath(), classFile);
    }
    Set<File> srcs = searchFile(new SuffixFilter("java"), dir);
    StringBuilder names = new StringBuilder(), paths = new StringBuilder();
    for (File src : srcs) {
        String classLocation = src.getAbsolutePath().substring(0, src.getAbsolutePath().length() - "java".length()) + "class";
        if (name2file.containsKey(classLocation)) {
            if (name2file.get(classLocation).lastModified() > src.lastModified()) {
                System.out.println("Cached: " + src.getName());
                continue;
            }
        }
        names.append(" ").append(src.getName());
        paths.append(" ").append(src.getAbsolutePath());
    }
    String clazzes = paths.toString();
    if (!clazzes.equals("")) {
        System.out.println("Compile: " + names.toString());
        BatchCompiler.compile(
                "-classpath rt.jar -g -warn:-unused -noExit -1.8 " + clazzes + " -d " + dir.getAbsolutePath(),
                new PrintWriter(System.out),
                new PrintWriter(System.err), null);
    }
}
 
Example 7
Project: LJFramework   File: FileUtils.java   View Source Code Vote up 6 votes
/**
 * 获取文件最后修改的毫秒时间戳
 *
 * @param file 文件
 * @return 文件最后修改的毫秒时间戳
 */
public static long getFileLastModified(File file) {
    if (file == null) {
        return -1;
    }
    return file.lastModified();
}
 
Example 8
Project: letv   File: MultiDexExtractor.java   View Source Code Vote up 6 votes
private static long getTimeStamp(File archive) {
    long timeStamp = archive.lastModified();
    if (timeStamp == -1) {
        return timeStamp - 1;
    }
    return timeStamp;
}
 
Example 9
Project: Reinickendorf_SER316   File: ResourcesTable.java   View Source Code Vote up 6 votes
public Object getValueAt(int row, int col) {
    Resource r = (Resource)files.get(row);
    if (col == _RESOURCE)
        return r;
    if (!r.isInetShortcut())  {
        File f = new File(r.getPath());
        switch (col) {
            case 0: return f.getName();
            case 1: MimeType mt = MimeTypesList.getMimeTypeForFile(f.getName());
                    if (mt != null) return mt.getLabel();
                    else return "unknown";
            case 2: Date d = new Date(f.lastModified());
                    return d;/*Local.getDateString(d, java.text.DateFormat.SHORT) +" "+
                           Local.getTimeString(d);*/
            case 3:return f.getPath();
        }
    }
    else {
        if (col == 0)
            return r.getPath();
        else if (col == 1)
            return Local.getString("Internet shortcut");
        else
            return "";                
    }
    return null;
}
 
Example 10
Project: EatDubbo   File: ResourceFilter.java   View Source Code Vote up 6 votes
private long getLastModified(String uri) {
    for (String resource : resources) {
           if (resource != null && resource.length() > 0) {
               String path = resource + uri;
               if (isFile(path)) {
                   File file = new File(path);
                   if (file.exists()) {
                       return file.lastModified();
                   }
               }
           }
       }
       return start;
}
 
Example 11
Project: ibm-cos-sdk-java   File: ProfilesConfigFile.java   View Source Code Vote up 6 votes
/**
 * Loads the AWS credential profiles from the file. The reference to the file is specified as a
 * parameter to the constructor.
 */
public ProfilesConfigFile(File file, ProfileCredentialsService credentialsService) throws
        SdkClientException {
    profileFile = ValidationUtils.assertNotNull(file, "profile file");
    profileCredentialsService = credentialsService;
    profileFileLastModified = file.lastModified();
    allProfiles = loadProfiles(profileFile);
}
 
Example 12
Project: jaffa-framework   File: CacheSourceMonitor.java   View Source Code Vote up 6 votes
/** This will monitor the files.
 */
private void monitor() {
    long time = System.currentTimeMillis() - m_millis;
    for (Iterator itr = m_files.iterator(); itr.hasNext(); ) {
        String fileName = (String) itr.next();
        File file = new File(fileName);
        if (!file.exists())
            continue;
        
        if (file.isFile()) {
            if (file.lastModified() > time) {
                if (log.isDebugEnabled())
                    log.debug(fileName + " has been modified. The Cache will be flushed.");
                m_cache.clear();
                break;
            }
        } else if (file.isDirectory()) {
            // Just monitor the files in the directory. We'll not be recursing thru the directory.
            File[] files = file.listFiles();
            for (int i = 0; i < files.length; i++) {
                file = files[i];
                if (file.isFile()) {
                    if (file.lastModified() > time) {
                        if (log.isDebugEnabled())
                            log.debug(file.getAbsolutePath() + " has been modified. The Cache will be flushed.");
                        m_cache.clear();
                        break;
                    }
                }
            }
        }
    }
}
 
Example 13
Project: gate-core   File: FSDirectory.java   View Source Code Vote up 5 votes
/** Returns the time the named file was last modified. */
@Override
public final long fileModified(String name) throws IOException {
  File file = new File(directory, name);
  return file.lastModified();
}
 
Example 14
Project: FallingUp   File: DownloaderActivity.java   View Source Code Vote up 5 votes
boolean expansionFilesUptoData() {

	File cacheFile = getFileDetailsCacheFile();
	// Read data into an array or something...
	Map<String, Long> fileDetailsMap = new HashMap<String, Long>();
	
	if(cacheFile.exists()) {
		try {
			FileReader fileCache = new FileReader(cacheFile);
			BufferedReader bufferedFileCache = new BufferedReader(fileCache);
			List<String> lines = new ArrayList<String>();
			String line = null;
			while ((line = bufferedFileCache.readLine()) != null) {
				lines.add(line);
			}
			bufferedFileCache.close();
			
			for(String dataLine : lines)
			{
				GameActivity.Log.debug("Splitting dataLine => " + dataLine);
				String[] parts = dataLine.split(",");
				fileDetailsMap.put(parts[0], Long.parseLong(parts[1]));
			}
		}
		catch(Exception e)
		{
			GameActivity.Log.debug("Exception thrown during file details reading.");
			e.printStackTrace();
			fileDetailsMap.clear();
		}	
	}
	
	for (OBBData.XAPKFile xf : OBBData.xAPKS) {
           String fileName = Helpers.getExpansionAPKFileName(this, xf.mIsMain, xf.mFileVersion);
		String fileForNewFile = Helpers.generateSaveFileName(this, fileName);
		String fileForDevFile = Helpers.generateSaveFileNameDevelopment(this, fileName);
		// check to see if time/data on files match cached version
		// if not return false
		File srcFile = new File(fileForNewFile);
		File srcDevFile = new File(fileForDevFile);
		long lastModified = srcFile.lastModified();
		long lastModifiedDev = srcDevFile.lastModified();
		if(!(srcFile.exists() && fileDetailsMap.containsKey(fileName) && lastModified == fileDetailsMap.get(fileName)) 
			&&
		   !(srcDevFile.exists() && fileDetailsMap.containsKey(fileName) && lastModifiedDev == fileDetailsMap.get(fileName)))
			return false;
	}
	return true;
}
 
Example 15
Project: hadoop   File: RawLocalFileSystem.java   View Source Code Vote up 5 votes
DeprecatedRawLocalFileStatus(File f, long defaultBlockSize, FileSystem fs) {
  super(f.length(), f.isDirectory(), 1, defaultBlockSize,
      f.lastModified(), new Path(f.getPath()).makeQualified(fs.getUri(),
        fs.getWorkingDirectory()));
}
 
Example 16
Project: stynico   File: Util.java   View Source Code Vote up 5 votes
public static FileInfo GetFileInfo(File f, FilenameFilter filter, boolean showHidden)
 {
FileInfo lFileInfo = new FileInfo();
String filePath = f.getPath();
File lFile = new File(filePath);
lFileInfo.canRead = lFile.canRead();
lFileInfo.canWrite = lFile.canWrite();
lFileInfo.isHidden = lFile.isHidden();
lFileInfo.fileName = f.getName();
lFileInfo.ModifiedDate = lFile.lastModified();
lFileInfo.IsDir = lFile.isDirectory();
lFileInfo.filePath = filePath;
if (lFileInfo.IsDir)
{
  int lCount = 0;
  File[] files = lFile.listFiles(filter);

  // null means we cannot access this dir
  if (files == null)
  {
	return null;
  }

  for (File child : files)
  {
	if ((!child.isHidden() || showHidden)
		&& Util.isNormalFile(child.getAbsolutePath()))
	{
	  lCount++;
	}
  }
  lFileInfo.Count = lCount;

}
else
{

  lFileInfo.fileSize = lFile.length();

}
return lFileInfo;
 }
 
Example 17
Project: truevfs   File: TBIO.java   View Source Code Vote up 5 votes
/** Unchecked parameters version. */
private static void
cp_r0(  final boolean preserve,
        final File src,
        final File dst,
        final TArchiveDetector srcDetector,
        final TArchiveDetector dstDetector)
throws IOException {
    if (src.isDirectory()) {
        final long srcLastModified = src.lastModified();
        final boolean srcArchived = src instanceof TFile
                && null != ((TFile) src).getInnerArchive();
        final boolean dstArchived = dst instanceof TFile
                && null != ((TFile) dst).getInnerArchive();
        final boolean srcIsGhost = srcArchived && 0 >= srcLastModified;
        if (!srcIsGhost || !dstArchived || !TConfig.current().isLenient())
            if (!dst.mkdir() && !dst.isDirectory())
                throw new NotDirectoryException(dst.getPath());
        final String[] members = src.list();
        if (null == members)
            throw new FileSystemException(dst.getPath(), null, "Cannot list directory!");
        if (!srcArchived && dstArchived) {
            // Create sorted entries if copying an ordinary directory to a
            // new archive.
            // This is a courtesy only, so natural order is sufficient.
            Arrays.sort(members);
        }
        for (final String member : members)
            cp_r0(  preserve,
                    new TFile(src, member, srcDetector),
                    new TFile(dst, member, dstDetector),
                    srcDetector, dstDetector);
        if (preserve && !srcIsGhost)
            if (!dst.setLastModified(srcLastModified))
                throw new FileSystemException(dst.getPath(), null, "Cannot set last modification time!");
    } else if (src.isFile()) {
        if (dst.exists() && !dst.isFile())
            throw new FileSystemException(dst.getPath(), null, "Not a file!");
        cp0(preserve, src, dst);
    } else if (src.exists()) {
        throw new FileSystemException(src.getPath(), null, "Cannot copy special file!");
    } else {
        throw new NoSuchFileException(src.getPath());
    }
}
 
Example 18
Project: gate-core   File: DocTimeReporter.java   View Source Code Vote up 3 votes
/**
 * Creates a FileWatcher on a given file.
 *
 * @param file
 *          A handle of the file to be watched.
 */
public FileWatcher(File file) {
  this.file = file;
  timeStamp = file.lastModified();
}
 
Example 19
Project: HeadlineNews   File: FileUtils.java   View Source Code Vote up 3 votes
/**
 * 获取文件最后修改的毫秒时间戳
 *
 * @param file 文件
 * @return 文件最后修改的毫秒时间戳
 */
public static long getFileLastModified(final File file) {
    if (file == null) return -1;
    return file.lastModified();
}
 
Example 20
Project: codedemos   File: FileUtil.java   View Source Code Vote up 3 votes
/**
 * 获取文件最后修改的毫秒时间戳
 *
 * @param file 文件
 * @return 文件最后修改的毫秒时间戳
 */
public static long getFileLastModified(File file) {
    if (file == null) return -1;
    return file.lastModified();
}