Based on the PosixFileAttributes class, you can extract the POSIX attributes - Java File Path IO

Java examples for File Path IO:Unix File

Description

Based on the PosixFileAttributes class, you can extract the POSIX attributes

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.PosixFileAttributes;

public class Main {
  public static void main(String[] args) {

    PosixFileAttributes attr = null;
    Path path = Paths.get("/home/folder1/folder2/folder3/test.txt");
    try {/*from   w ww.j a v a 2  s.co m*/
      attr = Files.readAttributes(path, PosixFileAttributes.class);
    } catch (IOException e) {
      System.err.println(e);
    }

    System.out.println("File owner: " + attr.owner().getName());
    System.out.println("File group: " + attr.group().getName());
    System.out.println("File permissions: " + attr.permissions().toString());
  }
}

Related Tutorials