Using the Files class' set/get POSIX file permission methods - Java File Path IO

Java examples for File Path IO:Unix File

Description

Using the Files class' set/get POSIX file permission methods

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.PosixFilePermission;
import java.util.Set;

public class Main {
  public static void main(String[] args) throws Exception {
    Path path = Paths.get("home/docs/users.txt");
    try {/*w w  w. j av a 2  s  .com*/
      Set<PosixFilePermission> permissions = Files
          .getPosixFilePermissions(path);
      System.out.print("Permissions: ");
      for (PosixFilePermission permission : permissions) {
        System.out.print(permission.name() + " ");
      }
      System.out.println();

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

Related Tutorials