public interface BasicFileAttributeView extends FileAttributeView
BasicFileAttributes接口定义。
文件的属性是从文件系统作为一个批量操作通过调用readAttributes方法。这个类也定义了setTimes方法更新文件的时间属性。
当需要动态访问文件属性时,此属性视图支持的属性有以下名称和类型:
Name Type "lastModifiedTime" FileTime"lastAccessTime" FileTime"creationTime" FileTime"size" Long"isRegularFile" Boolean"isDirectory" Boolean"isSymbolicLink" Boolean"isOther" Boolean"fileKey" Object
的getAttribute方法可以用来读取这些属性如果通过调用readAttributes()方法。
的setAttribute方法可用来更新文件的最后修改时间,最后访问时间、创建时间属性,如果通过调用setTimes方法。
| Modifier and Type | Method and Description |
|---|---|
String |
name()
返回属性视图的名称。
|
BasicFileAttributes |
readAttributes()
读取批量操作的基本文件属性。
|
void |
setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime)
更新文件最后一次修改的时间,最后一次访问时间,并创建时间属性。
|
String name()
"basic"观点。
name 接口
AttributeView
BasicFileAttributes readAttributes() throws IOException
它是实现特定的,如果所有的文件属性被读取作为一个原子操作相对于其他文件系统操作。
IOException如果I/O错误发生
SecurityException在默认提供程序的情况下,安装安全管理器,它的
checkRead方法被调用来检查对文件的读访问
void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime) throws IOException
这种方法更新文件的时间戳属性。将值转换为文件系统所支持的新纪元和精度。从细到粗粒度的结果在精度损失转换。此方法的行为试图设置一个时间戳,不支持或一个值超出由底层文件存储支持的范围不明确时。它可能会或不会抛出一个IOException。
如果有任何的lastModifiedTime,lastAccessTime,或createTime参数的值null那么相应的时间戳是不会改变的。一个实现可能需要读取文件的现有属性值时,只有一些,但不是全部,该时间戳属性更新。因此,这种方法可能不是一个原子操作相对于其他文件系统操作。阅读和重写现有的价值观也可能导致精度损失。如果所有的lastModifiedTime,lastAccessTime和createTime参数null那么这个方法没有效果。
使用示例:假设我们想改变一个文件的最后访问时间。
路径路径=…FileTime时间=…文件。getfileattributeview(路径,BasicFileAttributeView。类)。settimes(零时间,零);
lastModifiedTime -新的最后修改时间,或
null不改变值
lastAccessTime -最后的访问时间,或
null不改变值
createTime -文件的创建时间,或
null不改变值
IOException如果I/O错误发生
SecurityException在默认提供程序的情况下,安装安全管理器,它的
checkWrite方法被调用来检查文件的写访问
Files.setLastModifiedTime(java.nio.file.Path, java.nio.file.attribute.FileTime)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.