Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/java/nio/file/attribute/PosixFileAttributeView#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/nio/file/attribute/PosixFileAttributeView#inhmethods)

# PosixFileAttributeView

` public interface PosixFileAttributeView `   
` implements https://developer.android.com/reference/java/nio/file/attribute/BasicFileAttributeView, https://developer.android.com/reference/java/nio/file/attribute/FileOwnerAttributeView `

|---|
| java.nio.file.attribute.PosixFileAttributeView |

<br />

*** ** * ** ***

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](http://www.opengroup.org) 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 `https://developer.android.com/reference/java/nio/file/attribute/PosixFileAttributeView#readAttributes()` method is used to read the file's attributes. The file `https://developer.android.com/reference/java/nio/file/attribute/PosixFileAttributes#owner()` is represented by a `https://developer.android.com/reference/java/nio/file/attribute/UserPrincipal` that is the identity of the file owner for the purposes of access control. The `https://developer.android.com/reference/java/nio/file/attribute/PosixFileAttributes#group()`, represented by a `https://developer.android.com/reference/java/nio/file/attribute/GroupPrincipal`, 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 `https://developer.android.com/reference/java/nio/file/attribute/PosixFileAttributes#permissions()` attribute is a set of access permissions. This file attribute view provides access to the nine permission defined by the `https://developer.android.com/reference/java/nio/file/attribute/PosixFilePermission` 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 `https://developer.android.com/reference/java/nio/file/attribute/BasicFileAttributeView` and `https://developer.android.com/reference/java/nio/file/attribute/FileOwnerAttributeView`, and in addition, the following attributes are supported:
>
> | Name | Type |
> | "permissions" | `https://developer.android.com/reference/java/util/Set`\<`https://developer.android.com/reference/java/nio/file/attribute/PosixFilePermission`\> |
> | "group" | `https://developer.android.com/reference/java/nio/file/attribute/GroupPrincipal` |
> |---|---|
> [Supported attributes]

The `https://developer.android.com/reference/java/nio/file/Files#getAttribute(java.nio.file.Path,%20java.lang.String,%20java.nio.file.LinkOption[])` method may be used to read any of these attributes, or any of the attributes defined by `https://developer.android.com/reference/java/nio/file/attribute/BasicFileAttributeView` as if by invoking the `https://developer.android.com/reference/java/nio/file/attribute/PosixFileAttributeView#readAttributes()` method.

The `https://developer.android.com/reference/java/nio/file/Files#setAttribute(java.nio.file.Path,%20java.lang.String,%20java.lang.Object,%20java.nio.file.LinkOption[])` method may be used to update the file's last modified time, last access time or create time attributes as defined by `https://developer.android.com/reference/java/nio/file/attribute/BasicFileAttributeView`. It may also be used to update the permissions, owner, or group-owner as if by invoking the `https://developer.android.com/reference/java/nio/file/attribute/PosixFileAttributeView#setPermissions(java.util.Set<java.nio.file.attribute.PosixFilePermission>)`, `https://developer.android.com/reference/java/nio/file/attribute/FileOwnerAttributeView#setOwner(java.nio.file.attribute.UserPrincipal)`, and `https://developer.android.com/reference/java/nio/file/attribute/PosixFileAttributeView#setGroup(java.nio.file.attribute.GroupPrincipal)` 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 `https://developer.android.com/reference/java/nio/file/Files#createFile(java.nio.file.Path,%20java.nio.file.attribute.FileAttribute<?>[])` or `https://developer.android.com/reference/java/nio/file/Files#createDirectory(java.nio.file.Path,%20java.nio.file.attribute.FileAttribute<?>[])` methods as a `https://developer.android.com/reference/java/nio/file/attribute/FileAttribute` with `https://developer.android.com/reference/java/nio/file/attribute/FileAttribute#name()` `"posix:permissions"` and a `https://developer.android.com/reference/java/nio/file/attribute/FileAttribute#value()` that is the set of permissions. The following example uses the `https://developer.android.com/reference/java/nio/file/attribute/PosixFilePermissions#asFileAttribute(java.util.Set<java.nio.file.attribute.PosixFilePermission>)` method to construct a `FileAttribute` 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 `https://developer.android.com/reference/java/nio/file/Files#createFile(java.nio.file.Path,%20java.nio.file.attribute.FileAttribute<?>[])` or `https://developer.android.com/reference/java/nio/file/Files#createDirectory(java.nio.file.Path,%20java.nio.file.attribute.FileAttribute<?>[])` methods. In other words, the file may be more secure than requested.

## Summary

| ### Public methods ||
|---|---|
| ` abstract https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/nio/file/attribute/PosixFileAttributeView#name()() ` Returns the name of the attribute view. |
| ` abstract https://developer.android.com/reference/java/nio/file/attribute/PosixFileAttributes` | ` https://developer.android.com/reference/java/nio/file/attribute/PosixFileAttributeView#readAttributes()() ` Reads the basic file attributes as a bulk operation. |
| ` abstract void` | ` https://developer.android.com/reference/java/nio/file/attribute/PosixFileAttributeView#setGroup(java.nio.file.attribute.GroupPrincipal)(https://developer.android.com/reference/java/nio/file/attribute/GroupPrincipal group) ` Updates the file group-owner. |
| ` abstract void` | ` https://developer.android.com/reference/java/nio/file/attribute/PosixFileAttributeView#setPermissions(java.util.Set<java.nio.file.attribute.PosixFilePermission>)(https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/nio/file/attribute/PosixFilePermission> perms) ` Updates the file permissions. |

### Inherited methods

From interface ` https://developer.android.com/reference/java/nio/file/attribute/BasicFileAttributeView ` ` abstract https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/nio/file/attribute/BasicFileAttributeView#name()() `

Returns the name of the attribute view.
` abstract https://developer.android.com/reference/java/nio/file/attribute/BasicFileAttributes` ` https://developer.android.com/reference/java/nio/file/attribute/BasicFileAttributeView#readAttributes()() `

Reads the basic file attributes as a bulk operation.
` abstract void` ` https://developer.android.com/reference/java/nio/file/attribute/BasicFileAttributeView#setTimes(java.nio.file.attribute.FileTime,%20java.nio.file.attribute.FileTime,%20java.nio.file.attribute.FileTime)(https://developer.android.com/reference/java/nio/file/attribute/FileTime lastModifiedTime, https://developer.android.com/reference/java/nio/file/attribute/FileTime lastAccessTime, https://developer.android.com/reference/java/nio/file/attribute/FileTime createTime) `

Updates any or all of the file's last modified time, last access time, and create time attributes.
From interface ` https://developer.android.com/reference/java/nio/file/attribute/FileOwnerAttributeView ` ` abstract https://developer.android.com/reference/java/nio/file/attribute/UserPrincipal` ` https://developer.android.com/reference/java/nio/file/attribute/FileOwnerAttributeView#getOwner()() `

Read the file owner.
` abstract https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/nio/file/attribute/FileOwnerAttributeView#name()() `

Returns the name of the attribute view.
` abstract void` ` https://developer.android.com/reference/java/nio/file/attribute/FileOwnerAttributeView#setOwner(java.nio.file.attribute.UserPrincipal)(https://developer.android.com/reference/java/nio/file/attribute/UserPrincipal owner) `

Updates the file owner.
From interface ` https://developer.android.com/reference/java/nio/file/attribute/AttributeView ` ` abstract https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/nio/file/attribute/AttributeView#name()() `

Returns the name of the attribute view.

## Public methods

### name

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract String name ()
```

Returns the name of the attribute view. Attribute views of this type have the name `"posix"`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the name of the attribute view <br /> |

### readAttributes

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract PosixFileAttributes readAttributes ()
```

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.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/nio/file/attribute/PosixFileAttributes` | the file attributes <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |
| `https://developer.android.com/reference/java/lang/SecurityException` | In the case of the default provider, a security manager is installed, and it denies `https://developer.android.com/reference/java/lang/RuntimePermission``("accessUserInformation")` or its `https://developer.android.com/reference/java/lang/SecurityManager#checkRead(java.lang.String)` method denies read access to the file. |

### setGroup

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void setGroup (GroupPrincipal group)
```

Updates the file group-owner.

<br />

| Parameters ||
|---|---|
| `group` | `GroupPrincipal`: the new file group-owner <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs |
| `https://developer.android.com/reference/java/lang/SecurityException` | In the case of the default provider, and a security manager is installed, it denies `https://developer.android.com/reference/java/lang/RuntimePermission``("accessUserInformation")` or its `https://developer.android.com/reference/java/lang/SecurityManager#checkWrite(java.lang.String)` method denies write access to the file. |

### setPermissions

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void setPermissions (Set<PosixFilePermission> perms)
```

Updates the file permissions.

<br />

| Parameters ||
|---|---|
| `perms` | `Set`: the new set of permissions <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs |
| `https://developer.android.com/reference/java/lang/ClassCastException` | if the sets contains elements that are not of type `PosixFilePermission` |
| `https://developer.android.com/reference/java/lang/SecurityException` | In the case of the default provider, a security manager is installed, and it denies `https://developer.android.com/reference/java/lang/RuntimePermission``("accessUserInformation")` or its `https://developer.android.com/reference/java/lang/SecurityManager#checkWrite(java.lang.String)` method denies write access to the file. |