当前位置: 首页>>代码示例>>Java>>正文


Java File.setLastModified方法代码示例

本文整理汇总了Java中java.io.File.setLastModified方法的典型用法代码示例。如果您正苦于以下问题:Java File.setLastModified方法的具体用法?Java File.setLastModified怎么用?Java File.setLastModified使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.File的用法示例。


在下文中一共展示了File.setLastModified方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: touchFile

import java.io.File; //导入方法依赖的package包/类
public static void touchFile(final File parentDir, final String name) {
    final File file = new File(parentDir, name);
    try {
        if (!file.exists()) {
            if (!file.createNewFile()) {
                Timber.d("Unable to create file: %s", file.getAbsolutePath());
            }
        } else {
            if (!file.setLastModified(System.currentTimeMillis())) {
                Timber.d("Unable to change last modification date: %s", file.getAbsolutePath());
            }
        }
    } catch (Exception e) {
        Timber.d(e, "Unable to touch file: %s", file.getAbsolutePath());
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:17,代码来源:FileHelper.java

示例2: assertUnpacked

import java.io.File; //导入方法依赖的package包/类
public void assertUnpacked( ArtifactItem item, boolean overWrite )
    throws InterruptedException, MojoExecutionException
{

    File unpackedFile = getUnpackedFile( item );

    Thread.sleep( 100 );
    // round down to the last second
    long time = System.currentTimeMillis();
    time = time - ( time % 1000 );
    unpackedFile.setLastModified( time );

    assertEquals( time, unpackedFile.lastModified() );
    mojo.execute();

    if ( overWrite )
    {
        assertTrue( time != unpackedFile.lastModified() );
    }
    else
    {
        assertEquals( time, unpackedFile.lastModified() );
    }
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:25,代码来源:TestUnpackMojo.java

示例3: put

import java.io.File; //导入方法依赖的package包/类
@Override
public void put(String key, File file) {
	int valueSize = getSize(file);
	int curCacheSize = cacheSize.get();

	while (curCacheSize + valueSize > sizeLimit) {
		int freedSize = removeNext();
		if (freedSize == INVALID_SIZE) break; // cache is empty (have nothing to delete)
		curCacheSize = cacheSize.addAndGet(-freedSize);
	}
	cacheSize.addAndGet(valueSize);

	Long currentTime = System.currentTimeMillis();
	file.setLastModified(currentTime);
	lastUsageDates.put(file, currentTime);
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:17,代码来源:LimitedDiscCache.java

示例4: propertyChanged

import java.io.File; //导入方法依赖的package包/类
public void propertyChanged(Object source, int propId) {
	// When a property from the xslEditor Changes, walk the list all the listeners and notify them.
	Object listeners[] = listenerList.getListeners();
	for (int i = 0; i < listeners.length; i++) {
		IPropertyListener listener = (IPropertyListener) listeners[i];
		listener.propertyChanged(this, propId);
	}

	if (propId == IEditorPart.PROP_DIRTY) {
		if (!xmlEditor.isDirty()) {
			// We changed from Dirty to non dirty ==> User has saved so,
			// launch Convertigo engine

			// "touch" the parent style sheet ==> Convertigo engine will
			// recompile it
			
			IPath path;
			path = file.getRawLocation();
			path = path.append("../../" + parentStyleSheetUrl);
			File parentFile = path.toFile();
			parentFile.setLastModified(System.currentTimeMillis());
		}
	}
}
 
开发者ID:convertigo,项目名称:convertigo-eclipse,代码行数:25,代码来源:XslRuleEditor.java

示例5: discardCachesImpl

import java.io.File; //导入方法依赖的package包/类
private static void discardCachesImpl(AtomicLong al) {
    File user = Places.getUserDirectory();
    long now = System.currentTimeMillis();
    if (user != null) {
        File f = new File(user, ".lastModified");
        if (f.exists()) {
            f.setLastModified(now);
        } else {
            f.getParentFile().mkdirs();
            try {
                f.createNewFile();
            } catch (IOException ex) {
                LOG.log(Level.WARNING, "Cannot create " + f, ex);
            }
        }
    }
    if (al != null) {
        al.set(now);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:Stamps.java

示例6: packInternally

import java.io.File; //导入方法依赖的package包/类
@SuppressWarnings("CallToThreadDumpStack")
public static boolean packInternally(final File source,
        final File target) throws IOException {
    try {
        JarFile jarFile = new JarFile(source);
        FileOutputStream outputStream = new FileOutputStream(target);

        
        String output = "Packing jarFile: " + jarFile + " to " + target;
        if (project != null) {
            project.log("            " + output);
        } else {
            System.out.println(output);
        }

        packer.pack(jarFile, outputStream);

        jarFile.close();
        outputStream.close();
        target.setLastModified(source.lastModified());
    } catch (IOException exc) {
        exc.printStackTrace();
        return false;
    }
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:Utils.java

示例7: doCopyDirectory

import java.io.File; //导入方法依赖的package包/类
/**
 * Internal copy directory method.
 * 
 * @param srcDir  the validated source directory, must not be <code>null</code>
 * @param destDir  the validated destination directory, must not be <code>null</code>
 * @param filter  the filter to apply, null means copy all directories and files
 * @param preserveFileDate  whether to preserve the file date
 * @param exclusionList  List of files and directories to exclude from the copy, may be null
 * @throws IOException if an error occurs
 * @since Commons IO 1.1
 */
private static void doCopyDirectory(File srcDir, File destDir, FileFilter filter,
        boolean preserveFileDate, List<String> exclusionList) throws IOException {
    // recurse
    File[] srcFiles = filter == null ? srcDir.listFiles() : srcDir.listFiles(filter);
    if (srcFiles == null) {  // null if abstract pathname does not denote a directory, or if an I/O error occurs
        throw new IOException("Failed to list contents of " + srcDir);
    }
    if (destDir.exists()) {
        if (destDir.isDirectory() == false) {
            throw new IOException("Destination '" + destDir + "' exists but is not a directory");
        }
    } else {
        if (!destDir.mkdirs() && !destDir.isDirectory()) {
            throw new IOException("Destination '" + destDir + "' directory cannot be created");
        }
    }
    if (destDir.canWrite() == false) {
        throw new IOException("Destination '" + destDir + "' cannot be written to");
    }
    for (File srcFile : srcFiles) {
        File dstFile = new File(destDir, srcFile.getName());
        if (exclusionList == null || !exclusionList.contains(srcFile.getCanonicalPath())) {
            if (srcFile.isDirectory()) {
                doCopyDirectory(srcFile, dstFile, filter, preserveFileDate, exclusionList);
            } else {
                doCopyFile(srcFile, dstFile, preserveFileDate);
            }
        }
    }

    // Do this last, as the above has probably affected directory metadata
    if (preserveFileDate) {
        destDir.setLastModified(srcDir.lastModified());
    }
}
 
开发者ID:fesch,项目名称:Moenagade,代码行数:47,代码来源:FileUtils.java

示例8: touch

import java.io.File; //导入方法依赖的package包/类
/**
     * Make sure the timestamp on a file changes.
     * @param f a file to touch (make newer)
     * @param ref if not null, make f newer than this file; else make f newer than it was before
     */
    @SuppressWarnings("SleepWhileInLoop")
    public static void touch(File f, File ref) throws IOException, InterruptedException {
        long older = f.lastModified();
        if (ref != null) {
            older = Math.max(older, ref.lastModified());
        } else {
            older = Math.max(older, System.currentTimeMillis());
        }
        int maxPause = 9999;
        /* XXX consider this (as yet untested):
        long curr = System.currentTimeMillis();
        if (older > curr + maxPause) {
            throw new IllegalArgumentException("reference too far into the future, by " + (older - curr) + "msec");
        }
         */
        for (long pause = 1; pause < maxPause; pause *= 2) {
            Thread.sleep(pause);
            f.setLastModified(System.currentTimeMillis() + 1);  // plus 1 needed for FileObject tests (initially FO lastModified is set to currentTimeMillis)
            if (f.lastModified() > older) {
                while (f.lastModified() >= System.currentTimeMillis()) {
//                    LOG.log(Level.INFO, "Modification time is in future {0}", System.currentTimeMillis());
                    Thread.sleep(10);
                }
                return;
            }
        }
        Assert.fail("Did not manage to touch " + f);
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:TestFileUtils.java

示例9: downloadSuggestionsForQuery

import java.io.File; //导入方法依赖的package包/类
private File downloadSuggestionsForQuery(String query) {
	File cacheFile = new File(mContext.getCacheDir(), query.hashCode() + ".sgg");
	if (System.currentTimeMillis() - INTERVAL_DAY < cacheFile.lastModified()) {
		return cacheFile;
	}
	if (!isNetworkConnected(mContext)) {
		return cacheFile;
	}
	try {
		URL url = new URL("http://google.com/complete/search?q=" + query
				+ "&output=toolbar&hl=en");
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		connection.setDoInput(true);
		connection.connect();
		InputStream in = connection.getInputStream();

		if (in != null) {
			FileOutputStream fos = new FileOutputStream(cacheFile);
			int buffer;
			while ((buffer = in.read()) != -1) {
				fos.write(buffer);
			}
			fos.flush();
			fos.close();
		}
		cacheFile.setLastModified(System.currentTimeMillis());
	} catch (Exception e) {
		e.printStackTrace();
	}
	return cacheFile;
}
 
开发者ID:NewCasino,项目名称:browser,代码行数:32,代码来源:SearchAdapter.java

示例10: saveFileToCache

import java.io.File; //导入方法依赖的package包/类
private void saveFileToCache(File tempFile, long putTime, XulCacheModel data) {
	File file = new File(_cacheDir, data.getKey());
	tempFile.renameTo(file);
	file.setLastModified(putTime);
	data.setLastAccessTime(putTime);
	data.setData(file);
}
 
开发者ID:starcor-company,项目名称:starcor.xul,代码行数:8,代码来源:XulFileCache.java

示例11: get

import java.io.File; //导入方法依赖的package包/类
private File get(String key) {
    File file = newFile(key);
    Long currentTime = System.currentTimeMillis();
    file.setLastModified(currentTime);
    lastUsageDates.put(file, currentTime);

    return file;
}
 
开发者ID:syy555,项目名称:mvvm-clean,代码行数:9,代码来源:ACache.java

示例12: setFileModificationTime

import java.io.File; //导入方法依赖的package包/类
@Override
public void setFileModificationTime(
                                     String sourceFile,
                                     long lastModificationTime ) {

    File file = new File(sourceFile);
    checkFileExistence(file);

    if (!file.setLastModified(lastModificationTime)) {
        throw new FileSystemOperationException("Could not set last modification time for file '"
                                               + sourceFile + "'");
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:14,代码来源:LocalFileSystemOperations.java

示例13: testUnpackOverWriteIfNewer

import java.io.File; //导入方法依赖的package包/类
public void testUnpackOverWriteIfNewer()
    throws IOException, MojoExecutionException, InterruptedException
{
    stubFactory.setCreateFiles( true );
    Artifact artifact = stubFactory.getSnapshotArtifact();
    artifact.getFile().setLastModified( System.currentTimeMillis() - 2000 );

    ArtifactItem item = new ArtifactItem( artifact );

    ArrayList list = new ArrayList( 1 );
    list.add( item );
    mojo.setArtifactItems( list );
    mojo.setOverWriteIfNewer( true );
    mojo.execute();
    File unpackedFile = getUnpackedFile( item );

    // round down to the last second
    long time = System.currentTimeMillis();
    time = time - ( time % 1000 );
    // go back 10 more seconds for linux
    time -= 10000;
    // set to known value
    unpackedFile.setLastModified( time );
    // set source to be newer
    artifact.getFile().setLastModified( time + 4000 );

    // manually set markerfile (must match getMarkerFile in
    // DefaultMarkerFileHandler)
    File marker = new File( mojo.getMarkersDirectory(), artifact.getId().replace( ':', '-' ) + ".marker" );
    marker.setLastModified( time );

    assertTrue( time == unpackedFile.lastModified() );
    mojo.execute();
    assertTrue( time != unpackedFile.lastModified() );
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:36,代码来源:TestUnpackMojo.java

示例14: testTouchTime

import java.io.File; //导入方法依赖的package包/类
public void testTouchTime() throws IOException {
  File temp = createTempFile();
  assertTrue(temp.exists());
  temp.setLastModified(0);
  assertEquals(0, temp.lastModified());
  Files.touch(temp);
  assertThat(temp.lastModified()).isNotEqualTo(0);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:9,代码来源:FilesTest.java

示例15: download

import java.io.File; //导入方法依赖的package包/类
/**
 * Check if there is a new version of the script engine
 * 
 * @throws IOException
 *             if any error occur
 */
private void download() throws IOException {
    boolean is32 = "32".equals( System.getProperty( "sun.arch.data.model" ) );
    String fileName;
    final String os = System.getProperty( "os.name", "" ).toLowerCase();
    if( os.contains( "windows" ) ) {
        fileName = is32 ? "win32" : "win64";
    } else if( os.contains( "mac" ) ) {
        fileName = is32 ? "mac" : "mac64";
    } else if( os.contains( "linux" ) ) {
        fileName = is32 ? "linux-i686" : "linux-x86_64";
    } else {
        throw new IllegalStateException( "Unknown OS: " + os );
    }
    File target = new File( System.getProperty( "java.io.tmpdir" ) + "/SpiderMonkey" );
    URL url = new URL( "https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/jsshell-" + fileName
                    + ".zip" );
    System.out.println( "\tDownload: " + url );
    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
    if( target.exists() ) {
        System.out.println( "\tUP-TP-DATE" );
        conn.setIfModifiedSince( target.lastModified() );
    }
    InputStream input = conn.getInputStream();
    command = target.getAbsolutePath() + "/js";
    if( conn.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED ) {
        return;
    }
    ZipInputStream zip = new ZipInputStream( input );
    long lastModfied = conn.getLastModified();
    do {
        ZipEntry entry = zip.getNextEntry();
        if( entry == null ) {
            break;
        }
        if( entry.isDirectory() ) {
            continue;
        }
        File file = new File( target, entry.getName() );
        file.getParentFile().mkdirs();

        Files.copy( zip, file.toPath(), StandardCopyOption.REPLACE_EXISTING );
        file.setLastModified( entry.getTime() );
        if( "js".equals( file.getName() ) ) {
            file.setExecutable( true );
        }
    } while( true );
    target.setLastModified( lastModfied );
}
 
开发者ID:i-net-software,项目名称:JWebAssembly,代码行数:55,代码来源:SpiderMonkey.java


注:本文中的java.io.File.setLastModified方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。