集册 Java实例教程 可以使用名为group的POSIX属性设置文件组所有者。

可以使用名为group的POSIX属性设置文件组所有者。

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

396
可以使用名为group的POSIX属性设置文件组所有者。

import java.io.IOException;

import java.nio.file.Files;

import java.nio.file.Path;

import java.nio.file.Paths;/**来自 时 代 J     a    v  a - nowjava.com**/

import java.nio.file.attribute.GroupPrincipal;

import java.nio.file.attribute.PosixFileAttributeView;


public class Main {

  public static void main(String[] args) {


    Path path = Paths.get("/home/folder1/folder2/folder3/test.txt");

    try {

      GroupPrincipal group = path.getFileSystem()

          .getUserPrincipalLookupService()
          /*
          时 代 J a v a - N o w J a v a . c o m 提供
          */

          .lookupPrincipalByGroupName("apressteam");

      Files.getFileAttributeView(path, 
展开阅读全文