Ich habe es geschrieben, weil ich Berechtigungsänderungen in Java mit meiner Software codieren musste.
Ändern Sie die Berechtigungen der Datei, die in jede Zeile der Berechtigungsliste geschrieben wurde.
static ArrayList<String> permpaths;
public static void readPermissionList(){
permpaths = new ArrayList<>();
Path p = Paths.get("permission.list");
if(Files.exists(p)){
try {
FileReader fileReader = new FileReader(p.toFile());
BufferedReader bufferedReader = new BufferedReader(fileReader);
String data;
while ((data = bufferedReader.readLine()) != null) {
System.out.println(data);
permpaths.add(data);
}
fileReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}else{
permpaths.add("pocketmine.yml");
permpaths.add("server.properties");
permpaths.add("plugins/ChatPermitter.phar");
}
}
public static void setPermission(){
for(String filepath :permpaths) {
try {
Files.setPosixFilePermissions(Paths.get(filepath),
EnumSet.of(PosixFilePermission.OWNER_READ,
PosixFilePermission.OWNER_WRITE,
PosixFilePermission.OWNER_EXECUTE
));
} catch (IOException e) {
System.out.println("error");
}
https://stackoverflow.com/questions/48945147/how-to-change-permissions-to-incoming-file-in-linux-using-java http://kojiumeda.blogspot.com/2016/10/fileattribute.html http://kagamihoge.hatenablog.com/entry/20130110/1357810886
https://stackoverflow.com/questions/664432/how-do-i-programmatically-change-file-permissions
Recommended Posts