本文整理了Java中java.nio.file.Files.getLastModifiedTime()
方法的一些代码示例,展示了Files.getLastModifiedTime()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.getLastModifiedTime()
方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:getLastModifiedTime
暂无
代码示例来源:origin: spring-projects/spring-framework
/**
* This implementation returns the underlying File's timestamp.
* @see java.nio.file.Files#getLastModifiedTime(Path, java.nio.file.LinkOption...)
*/
@Override
public long lastModified() throws IOException {
// We can not use the superclass method since it uses conversion to a File and
// only a Path on the default file system can be converted to a File...
return Files.getLastModifiedTime(this.path).toMillis();
}
代码示例来源:origin: apache/nifi
@Override
public Object getCurrentState(final Path path) throws IOException {
return Files.getLastModifiedTime(path);
}
代码示例来源:origin: apache/kafka
private Long lastModifiedMs(String path) {
try {
return Files.getLastModifiedTime(Paths.get(path)).toMillis();
} catch (IOException e) {
log.error("Modification time of key store could not be obtained: " + path, e);
return null;
}
}
代码示例来源:origin: org.springframework/spring-core
/**
* This implementation returns the underlying File's timestamp.
* @see java.nio.file.Files#getLastModifiedTime(Path, java.nio.file.LinkOption...)
*/
@Override
public long lastModified() throws IOException {
// We can not use the superclass method since it uses conversion to a File and
// only a Path on the default file system can be converted to a File...
return Files.getLastModifiedTime(this.path).toMillis();
}
代码示例来源:origin: robolectric/robolectric
private static long getFileModDate(String path) {
try {
return Files.getLastModifiedTime(Paths.get(path)).toMillis();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: wildfly/wildfly
@Override
public Date getLastModified() {
try {
return new Date(Files.getLastModifiedTime(file).toMillis());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: neo4j/neo4j
@Override
public long lastModifiedTime( File file )
{
try
{
return Files.getLastModifiedTime( path( file ) ).toMillis();
}
catch ( IOException e )
{
return 0;
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* This implementation returns the underlying File/Path last-modified time.
*/
@Override
public long lastModified() throws IOException {
if (this.file != null) {
return super.lastModified();
}
else {
try {
return Files.getLastModifiedTime(this.filePath).toMillis();
}
catch (NoSuchFileException ex) {
throw new FileNotFoundException(ex.getMessage());
}
}
}
代码示例来源:origin: mpusher/mpush
private synchronized void writeToFile() {
try {
Files.write(cacheFile, Jsons.toJson(cache).getBytes(Constants.UTF_8));
this.lastModified = Files.getLastModifiedTime(cacheFile).toMillis();
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: mpusher/mpush
private synchronized void loadFormFile() {
try {
long lastModified = Files.getLastModifiedTime(cacheFile).toMillis();
if (this.lastModified < lastModified) {
byte[] bytes = Files.readAllBytes(cacheFile);
if (bytes != null && bytes.length > 0) {
cache = Jsons.fromJson(bytes, ConcurrentHashMap.class);
}
this.lastModified = lastModified;
}
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: oracle/helidon
private Instant getLastModified(String path) throws IOException {
Path file = Paths.get(path);
if (Files.exists(file) && Files.isRegularFile(file)) {
return Files.getLastModifiedTime(file).toInstant();
} else {
return null;
}
}
代码示例来源:origin: wildfly/wildfly
private void calculateChangeOverPoint() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.add(Calendar.DATE, 1);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
currentDateString = df.format(new Date());
// if there is an existing default log file, use the date last modified instead of the current date
if (Files.exists(defaultLogFile)) {
try {
currentDateString = df.format(new Date(Files.getLastModifiedTime(defaultLogFile).toMillis()));
} catch(IOException e){
// ignore. use the current date if exception happens.
}
}
changeOverPoint = calendar.getTimeInMillis();
}
代码示例来源:origin: MovingBlocks/Terasology
private static String getOldestFileName(final List<Path> paths) {
FileTime oldestTime = null;
Path oldestPath = null;
for (Path path : paths) {
try {
final FileTime fileTime = Files.getLastModifiedTime(path);
if (oldestTime == null || fileTime.compareTo(oldestTime) < 0) {
oldestTime = fileTime;
oldestPath = path;
}
} catch (IOException e) {
logger.error("Can't read last modified time for path {}", path);
}
}
if (oldestPath != null) {
return oldestPath.getFileName().toString();
}
return DEFAULT_PREVIEW_NAME;
}
代码示例来源:origin: oracle/helidon
/**
* Returns the last modified time of the given file or directory.
*
* @param path a file or directory
* @return the last modified time
*/
public static Instant lastModifiedTime(Path path) {
try {
return Files.getLastModifiedTime(path.toRealPath()).toInstant();
} catch (IOException e) {
LOGGER.log(Level.FINE, e, () -> "Cannot obtain the last modified time of '" + path + "'.");
}
Instant timestamp = Instant.MAX;
LOGGER.finer("Cannot obtain the last modified time. Used time '" + timestamp + "' as a content timestamp.");
return timestamp;
}
代码示例来源:origin: jphp-group/jphp
public static Memory filemtime(Environment env, TraceInfo trace, String path) {
Path file = Paths.get(path);
try {
return LongMemory.valueOf(Files.getLastModifiedTime(file).toMillis() / 1000);
} catch (IOException e) {
env.warning(trace, e.getMessage());
return Memory.FALSE;
} catch (UnsupportedOperationException e) {
return Memory.FALSE;
}
}
代码示例来源:origin: org.springframework/spring-core
/**
* This implementation returns the underlying File/Path last-modified time.
*/
@Override
public long lastModified() throws IOException {
if (this.file != null) {
return super.lastModified();
}
else {
try {
return Files.getLastModifiedTime(this.filePath).toMillis();
}
catch (NoSuchFileException ex) {
throw new FileNotFoundException(ex.getMessage());
}
}
}
代码示例来源:origin: oracle/helidon
static Instant resourceTimestamp(String resourceName) {
try {
Path resourcePath = resourcePath(resourceName);
if (resourcePath != null) {
return Files.getLastModifiedTime(resourcePath).toInstant();
}
} catch (Exception ex) {
LOGGER.log(Level.FINE, "Error to get resource '" + resourceName + "' last modified time.", ex);
}
return Instant.EPOCH;
}
}
代码示例来源:origin: jooby-project/jooby
@Override
public long getLastModified(final Path handle) {
return Try.apply(() -> Files.getLastModifiedTime(handle).toMillis()).orElse(-1L);
}
代码示例来源:origin: GoogleContainerTools/jib
@VisibleForTesting
LayerEntryTemplate(LayerEntry layerEntry) throws IOException {
sourceFile = layerEntry.getSourceFile().toAbsolutePath().toString();
extractionPath = layerEntry.getExtractionPath().toString();
lastModifiedTime = Files.getLastModifiedTime(layerEntry.getSourceFile()).toInstant();
permissions = layerEntry.getPermissions().toOctalString();
}
代码示例来源:origin: google/guava
public void testTouchTime() throws IOException {
Path temp = createTempFile();
assertTrue(Files.exists(temp));
Files.setLastModifiedTime(temp, FileTime.fromMillis(0));
assertEquals(0, Files.getLastModifiedTime(temp).toMillis());
MoreFiles.touch(temp);
assertThat(Files.getLastModifiedTime(temp).toMillis()).isNotEqualTo(0);
}
内容来源于网络,如有侵权,请联系作者删除!