-
- All Superinterfaces:
- AttributeView, BasicFileAttributeView, FileAttributeView, FileOwnerAttributeView
public interface PosixFileAttributeView extends BasicFileAttributeView, FileOwnerAttributeView
A file attribute view that provides a view of the file attributes commonly associated with files on file systems used by operating systems that implement the Portable Operating System Interface (POSIX) family of standards.Operating systems that implement the POSIX family of standards commonly use file systems that have a file owner, group-owner, and related access permissions. This file attribute view provides read and write access to these attributes.
The
readAttributes
method is used to read the file's attributes. The fileowner
is represented by aUserPrincipal
that is the identity of the file owner for the purposes of access control. Thegroup-owner
, represented by aGroupPrincipal
, is the identity of the group owner, where a group is an identity created for administrative purposes so as to determine the access rights for the members of the group.The
permissions
attribute is a set of access permissions. This file attribute view provides access to the nine permission defined by thePosixFilePermission
class. These nine permission bits determine the read, write, and execute access for the file owner, group, and others (others meaning identities other than the owner and members of the group). Some operating systems and file systems may provide additional permission bits but access to these other bits is not defined by this class in this release.Usage Example: Suppose we need to print out the owner and access permissions of a file:
Path file = ... PosixFileAttributes attrs = Files.getFileAttributeView(file, PosixFileAttributeView.class) .readAttributes(); System.out.format("%s %s%n", attrs.owner().getName(), PosixFilePermissions.toString(attrs.permissions()));
Dynamic Access
Where dynamic access to file attributes is required, the attributes supported by this attribute view are as defined by
BasicFileAttributeView
andFileOwnerAttributeView
, and in addition, the following attributes are supported:Name Type "permissions" Set
<PosixFilePermission
>"group" GroupPrincipal
The
getAttribute
method may be used to read any of these attributes, or any of the attributes defined byBasicFileAttributeView
as if by invoking thereadAttributes()
method.The
setAttribute
method may be used to update the file's last modified time, last access time or create time attributes as defined byBasicFileAttributeView
. It may also be used to update the permissions, owner, or group-owner as if by invoking thesetPermissions
,setOwner
, andsetGroup
methods respectively.Setting Initial Permissions
Implementations supporting this attribute view may also support setting the initial permissions when creating a file or directory. The initial permissions are provided to the
createFile
orcreateDirectory
methods as aFileAttribute
withname
"posix:permissions"
and avalue
that is the set of permissions. The following example uses theasFileAttribute
method to construct aFileAttribute
when creating a file:Path path = ... Set<PosixFilePermission> perms = EnumSet.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, GROUP_READ); Files.createFile(path, PosixFilePermissions.asFileAttribute(perms));
When the access permissions are set at file creation time then the actual value of the permissions may differ that the value of the attribute object. The reasons for this are implementation specific. On UNIX systems, for example, a process has a umask that impacts the permission bits of newly created files. Where an implementation supports the setting of the access permissions, and the underlying file system supports access permissions, then it is required that the value of the actual access permissions will be equal or less than the value of the attribute provided to the
createFile
orcreateDirectory
methods. In other words, the file may be more secure than requested.- Since:
- 1.7
-
-
Method Summary
Methods Modifier and Type Method and Description String
name()
Returns the name of the attribute view.PosixFileAttributes
readAttributes()
Reads the basic file attributes as a bulk operation.void
setGroup(GroupPrincipal group)
Updates the file group-owner.void
setPermissions(Set<PosixFilePermission> perms)
Updates the file permissions.-
Methods inherited from interface java.nio.file.attribute.BasicFileAttributeView
setTimes
-
-
-
-
Method Detail
-
name
String name()
Returns the name of the attribute view. Attribute views of this type have the name"posix"
.- Specified by:
name
in interfaceAttributeView
- Specified by:
name
in interfaceBasicFileAttributeView
- Specified by:
name
in interfaceFileOwnerAttributeView
-
readAttributes
PosixFileAttributes readAttributes() throws IOException
Description copied from interface:BasicFileAttributeView
Reads the basic file attributes as a bulk operation.It is implementation specific if all file attributes are read as an atomic operation with respect to other file system operations.
- Specified by:
readAttributes
in interfaceBasicFileAttributeView
- Returns:
- the file attributes
- Throws:
IOException
- if an I/O error occursSecurityException
- In the case of the default provider, a security manager is installed, and it deniesRuntimePermission
("accessUserInformation") or itscheckRead
method denies read access to the file.
-
setPermissions
void setPermissions(Set<PosixFilePermission> perms) throws IOException
Updates the file permissions.- Parameters:
perms
- the new set of permissions- Throws:
ClassCastException
- if the sets contains elements that are not of typePosixFilePermission
IOException
- if an I/O error occursSecurityException
- In the case of the default provider, a security manager is installed, and it deniesRuntimePermission
("accessUserInformation") or itscheckWrite
method denies write access to the file.
-
setGroup
void setGroup(GroupPrincipal group) throws IOException
Updates the file group-owner.- Parameters:
group
- the new file group-owner- Throws:
IOException
- if an I/O error occursSecurityException
- In the case of the default provider, and a security manager is installed, it deniesRuntimePermission
("accessUserInformation") or itscheckWrite
method denies write access to the file.
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-java/nio/file/attribute/posixfileattributeview.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.