Hello at all the community ! I'm tring to change the frequency clock of the cpu but i'm a problem. 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). 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? Thanks in advance.
You can't using Java 6.
You can using 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.
您可以尝试使用运行时,但正如fge所述,您可能无法在文件系统上设置权限。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.