Java PosixFileAttributes get file group name, owner name and permission

Description

Java PosixFileAttributes get file group name, owner name and permission

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFileAttributes;

public class Main {

  public static void main(String[] args) throws IOException {
    Path pUnix = Paths.get("/home/user/tmp/Main.txt");

    PosixFileAttributes fa = Files.readAttributes(pUnix, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS);

    // Unix specific, comment out if you're in Windows
    System.out.println("Group " + fa.group().getName());
    System.out.println("Owner " + fa.owner().getName());
    System.out.println("Permissions " + fa.permissions().toString());
  }//from  w  ww  . j a  v  a2s.  c o  m
}



PreviousNext

Related