[英]How can i set rwxrwxrwx permission using Java code?
Hello at all the community ! 大家好! I'm tring to change the frequency clock of the cpu but i'm a problem.
我想更改cpu的频率时钟,但我有问题。 To change the clock frequency i need to modify the file scaling_max_freq (/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq) but... this file has these permissions: rw-rw---- so with a file manager with root permissions i change rw-rw---- to rwxrwxrwx and all works fine (in this mode i can set the cpu frequency, with rw-rw---- permissions i can not do it).
要更改时钟频率,我需要修改scaling_max_freq文件(/ sys / devices / system / cpu / cpu0 / cpufreq / scaling_max_freq),但是...此文件具有以下权限:rw-rw ----因此使用文件管理器具有root权限,我将rw-rw ----更改为rwxrwxrwx,并且一切正常(在此模式下,我可以设置cpu频率,具有rw-rw ----权限,我无法做到)。 The code that i use for set the clock is this
我用来设置时钟的代码是这个
public static boolean setClock(String filePath, String value) {
try {
fileWriter = new FileWriter(filePath);
fileWriter.write(value);
fileWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
Now the question is: how can i set the permission for the file with code? 现在的问题是:我该如何使用代码设置文件的权限? how can i set rwxrwxrwx for the file scaling_max_freq?
如何为scaling_max_freq文件设置rwxrwxrwx? Thanks in advance.
提前致谢。
You can't using Java 6. 您不能使用Java 6。
You can using Java 7: 您可以使用Java 7:
Files.setPosixAttributes(path, EnumSet.allOf(PosixFilePermission.class));
Now the question is why. 现在的问题是为什么。 You normally should not do it at all.
通常,您根本不应该这样做。 Especially on a sysfs file.
特别是在sysfs文件上。
您可以尝试使用运行时,但正如fge所述,您可能无法在文件系统上设置权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.