語言

IPosixFileAttributeView 介面

定義

一個檔案屬性檢視,提供作業系統在實作可攜式作業系統介面(POSIX)標準家族時,常見於檔案系統檔案所關聯的檔案屬性視圖。

[Android.Runtime.Register("java/nio/file/attribute/PosixFileAttributeView", "", "Java.Nio.FileNio.Attributes.IPosixFileAttributeViewInvoker", ApiSince=26)]
public interface IPosixFileAttributeView : IDisposable, Java.Interop.IJavaPeerable, Java.Nio.FileNio.Attributes.IBasicFileAttributeView, Java.Nio.FileNio.Attributes.IFileOwnerAttributeView
[<Android.Runtime.Register("java/nio/file/attribute/PosixFileAttributeView", "", "Java.Nio.FileNio.Attributes.IPosixFileAttributeViewInvoker", ApiSince=26)>]
type IPosixFileAttributeView = interface
    interface IBasicFileAttributeView
    interface IFileAttributeView
    interface IAttributeView
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
    interface IFileOwnerAttributeView
屬性
實作

備註

一個檔案屬性檢視,提供作業系統在實作可攜式作業系統介面(POSIX)標準家族時,常見於檔案系統檔案所關聯的檔案屬性視圖。

實作 POSIX 標準家族的作業系統通常使用包含 file <em>owner</em>、 <em>群組擁有<者/em> 及相關 <em>存取權限</em> 的檔案系統。 此檔案屬性檢視提供對這些屬性的讀寫存取。

此 #readAttributes() readAttributes 方法用於讀取檔案的屬性。 PosixFileAttributes#owner() owner檔案以 a UserPrincipal 表示,這是檔案擁有者的身份,以便存取控制。 以 PosixFileAttributes#group() group-ownerGroupPrincipal表示的 ,是群組擁有者的身份,其中群組是為管理目的而建立的身份,用以確定群組成員的存取權限。

屬性 PosixFileAttributes#permissions() permissions 是一組存取權限。 此檔案屬性檢視提供類別定義 PosixFilePermission 的九個權限存取權限。 這九個權限位元決定<了檔案擁有者、群組及其他(指除擁有者和群組成員以外的身份)的 em>讀取</em><>、em write</em ><以及 em>< 執行/em> 存取權限。 部分作業系統與檔案系統可能會提供額外的權限位元,但此類別在此版本中並未定義對這些其他位元的存取。

<b>使用範例:</b> 假設我們需要列印一個檔案的擁有者與存取權限:

Path file = ...
                PosixFileAttributes attrs = Files.getFileAttributeView(file, PosixFileAttributeView.class)
                    .readAttributes();
                System.out.format("%s %s%n",
                    attrs.owner().getName(),
                    PosixFilePermissions.toString(attrs.permissions()));

<h2> 動態存取 </h2>

當需要對檔案屬性進行動態存取時,此屬性視圖所支援的屬性依定義為 和 ,此外,以下屬性也支援:blockquotetable class=“striped”caption style=“display:none” 支援屬性/caption theadtrth scope=“col” Name /thth scope=“col” 類型 /th/tr/theadtbody 翻譯th scope=「列」「權限」/thTD<>/結束/trtrth scope=“row” “group” /thtd/td/tr/tbody/table/blockquote

Files#getAttribute getAttribute此方法可用於讀取這些屬性中的任意一個,或由 定義BasicFileAttributeView的任意屬性,就像呼叫該#readAttributes readAttributes()方法一樣。

此 Files#setAttribute setAttribute 方法可用於更新檔案的最後修改時間、最後存取時間,或依定義 BasicFileAttributeView建立時間屬性。 它也可以用來更新權限、擁有者或群組擁有者,分別透過調用 #setPermissions setPermissions、 #setOwner setOwner和 #setGroup setGroup 方法來更新。

<h2> 設定初始權限 </h2>

支援此屬性檢視的實作,也可能支援在建立檔案或目錄時設定初始權限。 初始權限以 a 與Files#createFile createFileFiles#createDirectory createDirectorya FileAttribute 的形式提供給 FileAttribute#name name 或 "posix:permissions"FileAttribute#value value 方法,這是權限集合。 以下範例使用 PosixFilePermissions#asFileAttribute asFileAttribute 了在建立檔案時構造 a FileAttribute 的方法:

Path path = ...
                Set&lt;PosixFilePermission&gt; perms =
                    EnumSet.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, GROUP_READ);
                Files.createFile(path, PosixFilePermissions.asFileAttribute(perms));

當存取權限在檔案建立時設定時,權限的實際值可能會與屬性物件的值不同。 原因因實作而異。 以 UNIX 系統為例,程序有 <em>umask</em> ,會影響新建立檔案的權限位元。 當實作支援設定存取權限,且底層檔案系統支援存取權限時,則實際存取權限的值必須等於或小於提供給 Files#createFile createFile or Files#createDirectory createDirectory 方法的屬性值。 換句話說,檔案可能比申請的更安全。

在 1.7 版本中加入。

Java 文件 java.nio.file.attribute.PosixFileAttributeView。

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

屬性

名稱 Description
Handle

取得底層 Android 物件的 JNI 值。

(繼承來源 IJavaObject)
JniIdentityHashCode

回傳包裹實例的 java.lang.System.identityHashCode() 值。

(繼承來源 IJavaPeerable)
JniManagedPeerState

管理貴族的狀況。

(繼承來源 IJavaPeerable)
JniObjectReferenceControlBlock

一個檔案屬性檢視,提供作業系統在實作可攜式作業系統介面(POSIX)標準家族時,常見於檔案系統檔案所關聯的檔案屬性視圖。

(繼承來源 IJavaPeerable)
JniPeerMembers

成員存取與召喚支援。

(繼承來源 IJavaPeerable)
Owner

取得或設定檔案擁有者。

(繼承來源 IFileOwnerAttributeView)
PeerReference

回傳JniObjectReference包裹後的 Java 物件實例。

(繼承來源 IJavaPeerable)

方法

名稱 Description
Disposed()

當實例被處理後才被召喚。

(繼承來源 IJavaPeerable)
DisposeUnlessReferenced()

如果沒有未解決的參考資料,則 Dispose()呼叫;否則,則不做任何事。

(繼承來源 IJavaPeerable)
Finalized()

當實例完成後才會被通知。

(繼承來源 IJavaPeerable)
Name()

回傳屬性檢視的名稱。

ReadAttributes()

讀取 POSIX 檔案屬性作為一次批次操作。

SetGroup(IGroupPrincipal)

更新檔案群組擁有者。

SetJniIdentityHashCode(Int32)

將回傳的值設為 JniIdentityHashCode。

(繼承來源 IJavaPeerable)
SetJniManagedPeerState(JniManagedPeerStates)

一個檔案屬性檢視,提供作業系統在實作可攜式作業系統介面(POSIX)標準家族時,常見於檔案系統檔案所關聯的檔案屬性視圖。

(繼承來源 IJavaPeerable)
SetPeerReference(JniObjectReference)

將回傳的值設為 PeerReference。

(繼承來源 IJavaPeerable)
SetPermissions(ICollection<PosixFilePermission>)

更新檔案權限。

SetTimes(FileTime, FileTime, FileTime)

更新檔案中最後修改時間、最後存取時間,並建立時間屬性。

(繼承來源 IBasicFileAttributeView)
UnregisterFromRuntime()

取消註冊此實例,讓執行時不會在未來 Java.Interop.JniRuntime+JniValueManager.PeekValue 的呼叫中回傳該實例。

(繼承來源 IJavaPeerable)

擴充方法

名稱 Description
GetJniTypeName(IJavaPeerable)

取得實例 self類型的 JNI 名稱。

JavaAs<TResult>(IJavaPeerable)

試著強制self輸入 TResult,檢查 強制在 Java 端是否有效。

JavaCast<TResult>(IJavaObject)

執行 Android 執行時檢查型別轉換。

JavaCast<TResult>(IJavaObject)

一個檔案屬性檢視,提供作業系統在實作可攜式作業系統介面(POSIX)標準家族時,常見於檔案系統檔案所關聯的檔案屬性視圖。

TryJavaCast<TResult>(IJavaPeerable, TResult)

試著強制self輸入 TResult,檢查 強制在 Java 端是否有效。

適用於