Java FileOwnerAttributeView get owner

Description

Java FileOwnerAttributeView get owner

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileOwnerAttributeView;
import java.nio.file.attribute.UserPrincipal;

public class Main {

   public static void main(String[] args) {
      Path path = Paths.get("Main.java");
      try {//  ww w .  j av  a  2  s.  c om
         FileOwnerAttributeView view = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
         UserPrincipal userPrincipal = view.getOwner();
         System.out.println(userPrincipal.getName());

      } catch (IOException e) {
         e.printStackTrace();
      }
   }
}



PreviousNext

Related