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

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

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

475
您可以通过调用Files.setOwner()方法来设置文件所有者。

import java.io.IOException;

import java.nio.file.Files;

import java.nio.file.Path;//from N o w  J a v a  .   c o m

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");  
                                           /*
                                           来 自*
                                            时 代 J     a    v  a - nowjava.com
     
展开阅读全文