集册 Java实例教程 使用Files.setAttribute()设置文件所有者

使用Files.setAttribute()设置文件所有者

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

439
使用Files.setAttribute()设置文件所有者

import java.io.IOException;

import java.nio.file.Files;

import java.nio.file.LinkOption;

import java.nio.file.Path;/** from n o w j a   v  a . c o m - 时  代  Java**/

import java.nio.file.Paths;

import java.nio.file.attribute.UserPrincipal;


public class Main {

  public static void main(String[] args) {


    UserPrincipal owner = null;

    Path path = Paths.get("C:/folder1/folder2/folder4", "test.txt");

    try {

      owner = path.getFileSystem().getUserPrincipalLookupService().


      lookupPrincipalByName("apress");

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