Maintaining file ownership attributes using the FileOwnerAttributeView - Java File Path IO

Java examples for File Path IO:File Owner

Description

Maintaining file ownership attributes using the FileOwnerAttributeView

Demo Code

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("C:/home/docs/users.txt");
    try {/* w  w  w . j  a  va  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();
    }
  }

}

Related Tutorials