IPosixFileAttributeView 介面
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
檔案屬性檢視,提供通常與實作可攜式操作系統介面 (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 系列標準的操作系統通常會使用檔案 <em>owner/em>、<em>group-owner<</em> 和相關 <em>訪問許可權</em> 的文件系統。 這個檔案屬性檢視會提供這些屬性的讀取和寫入存取權。
方法 #readAttributes() readAttributes
可用來讀取檔案的屬性。 PosixFileAttributes#owner() owner
檔案是由 UserPrincipal
,這是訪問控制用途之檔案擁有者的身分識別。 PosixFileAttributes#group() group-owner
以 代表GroupPrincipal
的 是群組擁有者的身分識別,其中群組是針對系統管理用途所建立的身分識別,以便判斷群組成員的訪問許可權。
屬性 PosixFileAttributes#permissions() permissions
是一組訪問許可權。 這個檔案屬性檢視可讓您存取 類別所 PosixFilePermission
定義的九個許可權。 這九個許可權位會決定 <em read</em>、<em write</>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> Dynamic Access </h2>
如果需要動態存取檔案屬性,則此屬性檢視所支援的屬性如 和 所定義BasicFileAttributeView
,此外也支援下列屬性:<blockquote><table class=“striped”<>標題 style=“display:none”>Supported attributes</標題>< thead<>tr><th scope=“col”> Name </th scope=“col”> Type </th><>FileOwnerAttributeView
</Tr></thead><tbody><tr><th scope=“row” “permissions” <> /th><td>Set
<PosixFilePermission
> </td></tr><th><scope=“row” “group” <> /th><td/td<>><GroupPrincipal
/tr<>/tbody<>/table></blockquote>
方法Files#getAttribute getAttribute
可用來讀取任何這些屬性,或叫用 方法所BasicFileAttributeView
#readAttributes readAttributes()
定義的任何屬性。
方法 Files#setAttribute setAttribute
可用來更新檔案的上次修改時間、上次存取時間或建立時間屬性,如所 BasicFileAttributeView
定義。 它也可以用來分別叫 #setPermissions setPermissions
用、 #setOwner setOwner
和 #setGroup setGroup
方法來更新許可權、擁有者或群組擁有者。
<h2> 設定初始許可權 </h2>
支援此屬性檢視的實作也支援在建立檔案或目錄時設定初始許可權。 初始許可權會以和 FileAttribute#name name
"posix:permissions"
一FileAttribute#value value
組許可權的形式提供給 Files#createFile createFile
或 Files#createDirectory createDirectory
方法FileAttribute
。 下列範例會在 PosixFilePermissions#asFileAttribute asFileAttribute
建立檔案時使用 方法來建構 FileAttribute
:
Path path = ...
Set<PosixFilePermission> perms =
EnumSet.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, GROUP_READ);
Files.createFile(path, PosixFilePermissions.asFileAttribute(perms));
在檔案建立時設定訪問許可權時,許可權的實際值可能會與屬性物件的值不同。 這是實作特有的原因。 例如,在 UNIX 系統上,進程具有 <em>umask</em> ,會影響新建立檔案的許可權位。 如果實作支援訪問許可權的設定,而基礎文件系統支援訪問許可權,則必須實際訪問許可權的值等於或小於提供給 Files#createFile createFile
或 Files#createDirectory createDirectory
方法的屬性值。 換句話說,檔案可能比要求更安全。
已在1.7中新增。
的 java.nio.file.attribute.PosixFileAttributeView
Java 檔。
此頁面的部分是根據 所建立和共用的工作進行修改,並根據 2.5 屬性授權中所述的詞彙來使用。
屬性
Handle |
取得基礎 Android 物件的 JNI 值。 (繼承來源 IJavaObject) |
JniIdentityHashCode |
傳回已包裝實例的 值 |
JniManagedPeerState |
Managed 對等的狀態。 (繼承來源 IJavaPeerable) |
JniPeerMembers |
成員存取和調用支援。 (繼承來源 IJavaPeerable) |
Owner |
檔案屬性檢視,提供通常與實作可攜式操作系統介面 (POSIX) 系列標準之文件系統上檔案相關聯的檔案屬性檢視。 (繼承來源 IFileOwnerAttributeView) |
PeerReference |
傳 JniObjectReference 回已包裝 Java 物件實例的 。 (繼承來源 IJavaPeerable) |
方法
Disposed() |
處置實例時呼叫。 (繼承來源 IJavaPeerable) |
DisposeUnlessReferenced() |
如果這個實例沒有未完成的參考,則呼叫 |
Finalized() |
實例完成時呼叫。 (繼承來源 IJavaPeerable) |
Name() |
傳回屬性檢視的名稱。 |
ReadAttributes() |
檔案屬性檢視,提供通常與實作可攜式操作系統介面 (POSIX) 系列標準之文件系統上檔案相關聯的檔案屬性檢視。 |
SetGroup(IGroupPrincipal) |
匯報 檔案群組擁有者。 |
SetJniIdentityHashCode(Int32) |
設定所 |
SetJniManagedPeerState(JniManagedPeerStates) |
檔案屬性檢視,提供通常與實作可攜式操作系統介面 (POSIX) 系列標準之文件系統上檔案相關聯的檔案屬性檢視。 (繼承來源 IJavaPeerable) |
SetPeerReference(JniObjectReference) |
設定所 |
SetPermissions(ICollection<PosixFilePermission>) |
匯報 檔案許可權。 |
SetTimes(FileTime, FileTime, FileTime) |
匯報 任何或所有檔案上次修改的時間、上次存取時間和建立時間屬性。 (繼承來源 IBasicFileAttributeView) |
UnregisterFromRuntime() |
取消註冊這個實例,讓運行時間不會從未來的 Java.Interop.JniRuntime+JniValueManager.PeekValue 調用傳回它。 (繼承來源 IJavaPeerable) |
擴充方法
JavaCast<TResult>(IJavaObject) |
執行 Android 執行時間檢查的類型轉換。 |
JavaCast<TResult>(IJavaObject) |
檔案屬性檢視,提供通常與實作可攜式操作系統介面 (POSIX) 系列標準之文件系統上檔案相關聯的檔案屬性檢視。 |
GetJniTypeName(IJavaPeerable) |
檔案屬性檢視,提供通常與實作可攜式操作系統介面 (POSIX) 系列標準之文件系統上檔案相關聯的檔案屬性檢視。 |