简体   繁体   English

如何使用Java代码设置rwxrwxrwx权限?

[英]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.

相关问题 如何使用Java代码设置TextView的位置? - How can I set the position of a TextView using Java Code? 如何使用 Java 设置 AdUnitId? - How can I set AdUnitId using Java? 使用Rhino,如何将Java对象设置为执行JS代码的全局范围? - Using Rhino, how can I set a Java object as the global scope for executing JS code? 使用程序(JAVA 代码)运行 Jmeter 测试后如何保存结果集? - How can I save a result set after running the Jmeter Test using a program (JAVA CODE)? 如何在 java 的单行代码上设置计时器 - How I can set timer on a single line code in java 如何在调试 Java 代码时使用 Scanner 类对象在变量中设置值? - How can i set value in variable using Scanner class object while debugging Java code? 如何通过Java代码设置操作栏按钮图标 - How Can I set Action bar button icon by Java code 如何使用ImageIcon在Java swing中在背景中设置图像? - How can I set an image in the background with java swing using ImageIcon? 如何使用 java 代码为自定义代码创建编辑器 - How can I create an editor for a custom code using java code 如何使用java在更少的代码中使用switch case? - how can I use switch case in less code using java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM