集册 Java实例教程 管理POSIX属性

管理POSIX属性

欢马劈雪     最近更新时间:2020-01-02 10:19:05

526
管理POSIX属性
/**来自 
 时 代 J a v a**/

import java.nio.file.FileSystem;

import java.nio.file.Files;

import java.nio.file.Path;

import java.nio.file.Paths;

import java.nio.file.attribute.PosixFileAttributeView;

import java.nio.file.attribute.PosixFileAttributes;

import java.nio.file.attribute.PosixFilePermission;

import java.util.Set;


public class Main {

  public static void main(String[] args) throws Exception {

    Path path = Paths.get("home/docs/users.txt");

    PosixFileAttributeView view = Files.getFileAttributeView(path,

        PosixFileAttributeView.class);


    PosixFileAttributes attributes = view.readAttributes();

    Set<PosixFilePermission> permissions = attributes.permissions();

    listPermissions(permissions);//n o w    j a v a  . c o m 提供


    permissions.add(PosixFilePermission.OTHERS_WRITE);

    view.setPermissions(permissions);


    System.out.println();

    listPermissions(permissions);

  }


  private static void listPermissions(Set<PosixFilePermission> permissions)
展开阅读全文