public interface PosixFileAttributeView extends BasicFileAttributeView, FileOwnerAttributeView
操作系统,实施标准 POSIX家庭普遍使用的文件系统,文件的所有者,组所有者,和相关的访问权限。此文件属性视图提供了对这些属性的读写访问权限。
的readAttributes
方法用于读取文件的属性。文件owner
由UserPrincipal
是用于访问控制的目的文件的所有者代表的身份。的group-owner
,由GroupPrincipal
表示,是集团老板的身份,其中一组是为管理目的,以确定该组的成员的访问权限的身份。
的permissions
属性是一组访问权限。这个文件的属性视图提供了访问九经PosixFilePermission
类定义。这九个权限位决定了文件所有者、组和其他人(他人的意义身份以外的所有者和组成员)的读、写和执行访问权限。一些操作系统和文件系统可能提供额外的权限位,但在这个版本中,访问这些其他位不是由这个类定义的。
使用示例:假设我们需要打印一个文件的所有者和访问权限:
路径文件=…posixfileattributes属性=文件。getfileattributeview(文件,posixfileattributeview。类)readattributes();系统。格式(“% s %的% s”,属性。owner()。getname(),posixfilepermissions ToString(属性。permissions()));
在文件属性的动态访问是必需的,通过这个属性视图支持的属性是由BasicFileAttributeView
和FileOwnerAttributeView
定义,此外,以下属性的支持:
Name Type "permissions" Set
<PosixFilePermission
>"group" GroupPrincipal
的getAttribute
方法可以用来读取这些属性,或属性定义的BasicFileAttributeView
仿佛被调用readAttributes()
方法。
的setAttribute
方法可用来更新文件的最后修改时间,最后访问时间、创建时间属性所定义的BasicFileAttributeView
。它也可以用来更新的权限,所有者,或组所有者如果通过调用setPermissions
,setOwner
,和setGroup
方法分别。
支持此属性视图的实现也可以支持在创建一个文件或目录时设置初始权限。初始权限提供给createFile
或createDirectory
方法作为一个name
"posix:permissions"
和value
是权限集FileAttribute
。下面的例子使用了asFileAttribute
构造方法创建一个文件时,FileAttribute
:
路径路径=…集<< posixfilepermission >烫发=EnumSet,(owner_read,owner_write,owner_execute,group_read);文件。CreateFile(路径,posixfilepermissions。asfileattribute(权限));
当在文件创建时间设置访问权限时,权限的实际值可能会有所不同,属性对象的值可能会有所不同。这是实现具体的原因。例如,Unix系统,一个进程有一个umask影响新创建的文件的权限位。在一个实施支持访问权限的设置,和底层文件系统支持的访问权限,那么它需要的实际访问权限的值将等于或低于提供给createFile
createDirectory
方法或属性值。换言之,该文件可能比请求更安全。
Modifier and Type | Method and Description |
---|---|
String |
name()
返回属性视图的名称。
|
PosixFileAttributes |
readAttributes()
读取批量操作的基本文件属性。
|
void |
setGroup(GroupPrincipal group)
更新文件组所有者。
|
void |
setPermissions(Set<PosixFilePermission> perms)
更新文件权限。
|
setTimes
getOwner, setOwner
String name()
"posix"
观点。
name
接口
AttributeView
name
接口
BasicFileAttributeView
name
接口
FileOwnerAttributeView
PosixFileAttributes readAttributes() throws IOException
BasicFileAttributeView
它是实现特定的,如果所有的文件属性被读取作为一个原子操作相对于其他文件系统操作。
readAttributes
接口
BasicFileAttributeView
IOException
如果I/O错误发生
SecurityException
在默认提供程序的情况下,安装安全管理器,它否认
RuntimePermission
("accessUserInformation")或其
checkRead
法否认对文件的读访问。
void setPermissions(Set<PosixFilePermission> perms) throws IOException
perms
-权限的新组
ClassCastException
如果集包含不
PosixFilePermission
型元素
IOException
如果I/O错误发生
SecurityException
在默认提供程序的情况下,安装安全管理器,它否认
RuntimePermission
("accessUserInformation")或其
checkWrite
方法拒绝写访问文件。
void setGroup(GroupPrincipal group) throws IOException
group
-新文件的组所有者
IOException
如果I/O错误发生
SecurityException
在默认提供程序的情况下,和安全管理器安装,它否认
RuntimePermission
("accessUserInformation")或其
checkWrite
方法拒绝写访问文件。
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.