Get a File Owner Using FileOwnerAttributeView.getOwner() - Java File Path IO

Java examples for File Path IO:File Owner

Description

Get a File Owner Using FileOwnerAttributeView.getOwner()

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;

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 {//from w  w  w.j a v  a2s  . com
      String owner = foav.getOwner().getName();
      System.out.println(owner);
    } catch (IOException e) {
      System.err.println(e);
    }

  }
}

Result


Related Tutorials