集册 Java实例教程 使用FileOwnerAttributeView.getOwner()获取文件所有者

使用FileOwnerAttributeView.getOwner()获取文件所有者

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

477
使用FileOwnerAttributeView.getOwner()获取文件所有者

import java.io.IOException;/** 来自 n o w j a   v  a . c o m - 时  代  Java**/

import java.nio.file.Files;

import java.nio.file.Path;

import java.nio.file.Paths;

import java.nio.file.attribute.FileOwnerAttributeView;


public class Main {

  public static void main(String[] args) {


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

    FileOwnerAttributeView foav = Files.getFileAttributeView(path,

        FileOwnerAttributeView.class);

    try {

      String owner = foav.getOwner().getName();

 
展开阅读全文