Java IO Tutorial - Java PosixFilePermissions .fromString (String perms)








Syntax

PosixFilePermissions.fromString(String perms) has the following syntax.

public static Set < PosixFilePermission > fromString(String perms)

Example

In the following code shows how to use PosixFilePermissions.fromString(String perms) method.

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set;
/*from   w w w . jav  a 2 s . co m*/
public class Main {

  public static void main(String[] args) throws Exception {

    Path path = Paths.get("c:/home/tutorial/Java/JavaFX/Topic.txt");
    Path new_path = Paths.get("/home/tutorial/Java/JavaFX/new_Topic.txt");

    //use of fromString
    Set<PosixFilePermission> permissions = PosixFilePermissions.fromString("rw-r--r--");
    try {
        Files.setPosixFilePermissions(new_path, permissions);
    } catch (IOException e) {
        System.err.println(e);
    }
  }
}