Using the Files class' setAttribute method - Java File Path IO

Java examples for File Path IO:File Attribute

Description

Using the Files class' setAttribute method

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;

public class Main {
  public static void main(String[] args) throws Exception {
    Path path = Paths.get("home/docs/users.txt");
    try {//  w  w w. j a v a 2 s  .  co  m
      Files.setAttribute(path, "posix:permission",
          PosixFilePermission.OTHERS_WRITE);
    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }
}

Related Tutorials