files - File Systems

Two methods find out the rest of the information about the file system.

  • get the "default" file system using static FileSystems utility
  • call getFileSystem() on a Path object to get the file system that created that Path.
// files/FileSystemDemo.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.

import java.nio.file.*;

public class FileSystemDemo {
  static void show(String id, Object o) {
    System.out.println(id + ": " + o);
  }

  public static void main(String[] args) {
    System.out.println(System.getProperty("os.name"));
    FileSystem fsys = FileSystems.getDefault();
    for (FileStore fs : fsys.getFileStores()) {
      show("File Store", fs);
    }
    for (Path rd : fsys.getRootDirectories()) {
      show("Root Directory", rd);
    }
    show("Separator", fsys.getSeparator());
    show("UserPrincipalLookupService", fsys.getUserPrincipalLookupService());
    show("isOpen", fsys.isOpen());
    show("isReadOnly", fsys.isReadOnly());
    show("FileSystemProvider", fsys.provider());
    show("File Attribute Views", fsys.supportedFileAttributeViews());
  }
}
/* Output:
Windows 10
File Store: SSD (C:)
Root Directory: C:\
Root Directory: D:\
Separator: \
UserPrincipalLookupService:
sun.nio.fs.WindowsFileSystem$LookupService$1@15db9742
isOpen: true
isReadOnly: false
FileSystemProvider:
sun.nio.fs.WindowsFileSystemProvider@6d06d69c
File Attribute Views: [owner, dos, acl, basic, user]
*/

 

public abstract class FileStore
extends Object

Storage for files. A FileStore represents a storage pool, device, partition, volume, concrete file system or other implementation specific means of file storage. The FileStore for where a file is stored is obtained by invoking the getFileStore method, or all file stores can be enumerated by invoking the getFileStores method.

In addition to the methods defined by this class, a file store may support one or more FileStoreAttributeView classes that provide a read-only or updatable view of a set of file store attributes.

Since:

1.7

 

getUserPrincipalLookupService

public abstract UserPrincipalLookupService getUserPrincipalLookupService()

Returns the UserPrincipalLookupService for this file system (optional operation). The resulting lookup service may be used to lookup user or group names.

Usage Example: Suppose we want to make "joe" the owner of a file:

     UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
     Files.setOwner(path, lookupService.lookupPrincipalByName("joe"));
 

Returns:

The UserPrincipalLookupService for this file system

Throws:

UnsupportedOperationException - If this FileSystem does not does have a lookup service

 

references:

1. On Java 8 - Bruce Eckel

2. https://github.com/wangbingfeng/OnJava8-Examples/blob/master/files/FileSystemDemo.java

3. https://docs.oracle.com/javase/8/docs/api/java/nio/file/FileStore.html

4. https://docs.oracle.com/javase/8/docs/api/java/nio/file/FileSystem.html#getUserPrincipalLookupService--

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值