Here you can find the source of givePerm(File f, Set
Parameter | Description |
---|---|
f | The file/directory to apply permissions on. |
perms | The POSIX permissions as string |
private static boolean givePerm(File f, Set<PosixFilePermission> perms)
//package com.java2s; //License from project: Open Source License import java.io.File; 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 { private static String OS = System.getProperty("os.name").toLowerCase(); /**/*from w w w . j a v a 2 s . c om*/ * Sets specified permissions to a single file or directory. * * @param f * The file/directory to apply permissions on. * @param perms * The POSIX permissions as string * @return True if file permissions were applied */ private static boolean givePerm(File f, Set<PosixFilePermission> perms) { try { Path p = Paths.get(f.toURI()); if (OS.indexOf("win") >= 0) { // just set writable on windows I guess... p.toFile().setWritable(true); } else { Files.setPosixFilePermissions(p, perms); } } catch (IOException e) { System.err.printf("Could not set permissions '%s' to %s\n", perms, f.toString()); return false; } return true; } }