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:de.jwi.jfm.FileWrapper.java

public String getLastModified() {
    File file = getFile();
    long l = file.lastModified();
    String s = folder.dateFormat.format(new Date(l));
    return s;// ww  w . j  a v a 2  s .co  m
}

From source file:com.jalios.ejpt.sync.utils.IOUtil.java

/**
 * Copy f1 into f2 (mkdirs for f2)/*from w  w w  .  j  ava 2 s . c o m*/
 * 
 * @param f1
 *          the source file
 * @param f2
 *          the target file
 * @throws IOException
 */
public static void copyFile(File f1, File f2) throws IOException {
    if (f1 == null || f2 == null) {
        throw new IllegalArgumentException("f1 and f2 arguments must not be null");
    }

    // Create target directories
    if (f2.getParentFile() != null) {
        f2.getParentFile().mkdirs();
    }

    // Copy
    InputStream input = null;
    OutputStream output = null;
    try {
        input = new FileInputStream(f1);
        output = new FileOutputStream(f2);
        IOUtils.copy(input, output);
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException ex) {
            }
        }
        if (output != null) {
            try {
                output.close();
            } catch (IOException ex) {
            }
        }
    }
    f2.setLastModified(f1.lastModified());

}

From source file:com.migratebird.script.repository.impl.FileSystemScriptLocation.java

/**
 * Creates a script object for the given script file
 *
 * @param scriptFile             the script file, not null
 * @param relativeScriptFileName the name of the script file relative to the root scripts dir, not null
 * @return The script, not null//  w w  w  .  j  av  a 2 s . c o m
 */
protected Script createScript(File scriptFile, String relativeScriptFileName) {
    Long fileLastModifiedAt = scriptFile.lastModified();
    ScriptContentHandle scriptContentHandle = new ScriptContentHandle.UrlScriptContentHandle(
            FileUtils.getUrl(scriptFile), scriptEncoding, ignoreCarriageReturnsWhenCalculatingCheckSum);
    return scriptFactory.createScriptWithContent(relativeScriptFileName, fileLastModifiedAt,
            scriptContentHandle);
}

From source file:manipulaxmls.Copiar.java

public void copiarXml(String origemNfe) {

    File diretorio;
    diretorio = new File(origemNfe);
    if (diretorio.exists()) {
        Date modifica = new Date(diretorio.lastModified());
        System.out.println("ultima modificacao: " + modifica);

        File[] lista = diretorio.listFiles();
        File destino = new File(System.getProperty("user.home") + "\\desktop\\contador");
        if (destino.exists()) {

        } else {/*from  w w w  .j  a v a 2  s  . c o m*/
            destino.mkdir();
        }
        for (File lista1 : lista) {

            Date dataArq = new Date(lista1.lastModified());
            int anoArq = dataArq.getYear() + 1900;
            int mesArq = dataArq.getMonth() + 1;
            File pastaAno = new File(System.getProperty("user.home") + "\\desktop\\contador" + "\\" + anoArq);
            File pastaMes = new File(
                    System.getProperty("user.home") + "\\desktop\\contador" + "\\" + anoArq + "\\" + mesArq);
            if (pastaAno.exists()) {

            } else {
                pastaAno.mkdir();
            }
            if (pastaMes.exists()) {

            } else {
                pastaMes.mkdir();
            }
            String nomeArq = lista1.getName();
            if (nomeArq.length() == 51) {
                try {

                    destino = pastaMes;
                    FileUtils.copyFileToDirectory(lista1, destino);

                } catch (Exception ex) {
                    System.out.println("ERRO! " + ex);
                }
            }
        }
    } else {
        System.out.println("CAMINHO INEXISTENTE !!!");
        System.out.println("diretorio :" + diretorio);
    }
}

From source file:com.marc.lastweek.business.services.images.impl.ImageServiceImpl.java

public Date getLastModifyTime(ImageEntry imageEntry) {
    File f = new File(imageEntry.getFileName());
    return new Date(f.lastModified());
}

From source file:net.mozq.picto.core.ProcessCore.java

private static Date getPhotoTakenDate(Path imagePath, ImageMetadata imageImageMetadata) {
    File imageFile = imagePath.toFile();

    Date photoTakenDate;/*www  . j a v a 2  s  .co m*/
    try {
        photoTakenDate = getExifDate(imageImageMetadata);
    } catch (IOException e) {
        photoTakenDate = null;
    }

    if (photoTakenDate == null) {
        photoTakenDate = new Date(imageFile.lastModified());
    }

    return photoTakenDate;
}

From source file:edu.umn.msi.tropix.labs.requests.rdm.ProcessClosureImpl.java

public void apply(final File input) {
    try {/*from w w  w.j  a  va2s .c  o  m*/
        if (processTracker.beenProcessed(input)) {
            return;
        }
        final long lastModified = input.lastModified();
        final long now = System.currentTimeMillis();
        if (lastModified + waitTime > now) {
            return;
        }
        uploadClosure.apply(input);
        try {
            processTracker.process(input);
        } catch (final Throwable t) {
            ExceptionUtils.logQuietly(LOG, t, "Failed to tell process tracker that file " + input
                    + " has been processed, it will likely be reprocessed.");
        }
    } catch (final RuntimeException e) {
        ExceptionUtils.logQuietly(LOG, e);
    }
}

From source file:com.virtualparadigm.packman.processor.JPackageManagerOld.java

public static boolean configureCommons(File tempDir, Configuration configuration) {
    logger.info("PackageManager::configure()");
    boolean status = true;
    if (tempDir != null && configuration != null && !configuration.isEmpty()) {

        Map<String, String> substitutionContext = JPackageManagerOld.createSubstitutionContext(configuration);
        StrSubstitutor strSubstitutor = new StrSubstitutor(substitutionContext);
        String templateContent = null;
        long lastModified;

        Collection<File> patchFiles = FileUtils.listFiles(
                new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.PATCH_DIR_NAME + "/"
                        + JPackageManagerOld.PATCH_FILES_DIR_NAME),
                TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY);

        if (patchFiles != null) {
            for (File pfile : patchFiles) {
                logger.debug("  processing patch fileset file: " + pfile.getAbsolutePath());
                try {
                    lastModified = pfile.lastModified();
                    templateContent = FileUtils.readFileToString(pfile);
                    templateContent = strSubstitutor.replace(templateContent);
                    FileUtils.writeStringToFile(pfile, templateContent);
                    pfile.setLastModified(lastModified);
                } catch (Exception e) {
                    e.printStackTrace();
                }/*from  w ww.j  ava  2  s.c  o m*/
            }
        }

        Collection<File> scriptFiles = FileUtils.listFiles(
                new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.AUTORUN_DIR_NAME),
                TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY);

        if (scriptFiles != null) {
            for (File scriptfile : scriptFiles) {
                logger.debug("  processing script file: " + scriptfile.getAbsolutePath());
                try {
                    lastModified = scriptfile.lastModified();
                    templateContent = FileUtils.readFileToString(scriptfile);
                    templateContent = strSubstitutor.replace(templateContent);
                    FileUtils.writeStringToFile(scriptfile, templateContent);
                    scriptfile.setLastModified(lastModified);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return status;
}

From source file:info.magnolia.cms.servlets.Spool.java

/**
 * This makes browser and proxy caches work more effectively, reducing the load on server and network resources.
 *
 * @param request HttpServletRequest//from www . j  av  a  2 s  .  co m
 * @return last modified time in miliseconds since 1st Jan 1970 GMT
 */
public long getLastModified(HttpServletRequest request) {
    File resource = new File(getServletContext().getRealPath(Path.getURI(request)));
    if (resource.exists()) {
        return resource.lastModified();
    }
    return -1;
}

From source file:MaximumFileFilter.java

/**
 * {@inheritDoc}/*ww w.j ava2 s  .  c  om*/
 */
public boolean accept(File dir, String name) {
    File currentFile = new File(dir, name);

    if (currentFile.isDirectory()) {
        return false;
    }
    if ((m_dtOlderThan != null) && (currentFile.lastModified() > m_dtOlderThan.getTime())) {
        return false;
    }
    if ((m_iMaximum == 0) || (m_currentFileCount <= m_iMaximum)) {
        m_currentFileCount++;
    }
    return m_currentFileCount <= m_iMaximum;
}