Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么猫<;文件>;“给我”;无效参数";?_Java_Android_Cpu Usage_Power Management - Fatal编程技术网

Java 为什么猫<;文件>;“给我”;无效参数";?

Java 为什么猫<;文件>;“给我”;无效参数";?,java,android,cpu-usage,power-management,Java,Android,Cpu Usage,Power Management,我正在尝试编写一个Android应用程序来收集设备的使用统计数据(只是为了了解Android的开发和工作原理,我还是个新手)。我现在想知道的是我的设备核心的频率(它有4个核心) 我正在努力 cat /sys/devices/system/cpu/cpu*/cpufreq/cpuinfo_cur_freq OR cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq 但是在从cpu

我正在尝试编写一个Android应用程序来收集设备的使用统计数据(只是为了了解Android的开发和工作原理,我还是个新手)。我现在想知道的是我的设备核心的频率(它有4个核心)

我正在努力

cat /sys/devices/system/cpu/cpu*/cpufreq/cpuinfo_cur_freq
                            OR
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq
但是在从cpu0获取值之后,它似乎不起作用。我并没有让应用程序崩溃,但我已经尝试了很多事情,包括在终端上乱搞,它告诉我我给了它一个无效的论点。我将包括下面的代码,如果有人可以帮助,你会很棒

try {    
        //Process process = Runtime.getRuntime().exec("su");
        RandomAccessFile reader = new RandomAccessFile
                ("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "r");
        String load = reader.readLine();
        freqs[0] = Integer.parseInt(load);
        reader = new RandomAccessFile
                ("/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq", "r");
        load = reader.readLine();
        freqs[1] = Integer.parseInt(load);
        reader = new RandomAccessFile
                ("/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq", "r");
        load = reader.readLine();
        freqs[2] = Integer.parseInt(load);
        reader = new RandomAccessFile
                ("/sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq", "r");
        load = reader.readLine();
        freqs[3] = Integer.parseInt(load);

       //A for loop I had tried and failed to implement

        /*RandomAccessFile reader = null;
        for (i = 0; i < cores; i++){
            reader = new RandomAccessFile("/sys/devices/system/cpu/cpu" + i 
                    + "/cpufreq/cpuinfo_cur_freq", "r");
            String load = reader.readLine();
            freqs[i] = Integer.parseInt(load);
        }*/         

    } catch (IOException ex) {
        ex.printStackTrace();
    }
试试{
//Process Process=Runtime.getRuntime().exec(“su”);
RandomAccessFile reader=新的RandomAccessFile
(“/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq”、“r”);
字符串加载=reader.readLine();
freqs[0]=整数.parseInt(加载);
reader=新的随机访问文件
(“/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq”、“r”);
load=reader.readLine();
freqs[1]=整数.parseInt(加载);
reader=新的随机访问文件
(“/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq”,“r”);
load=reader.readLine();
freqs[2]=整数.parseInt(加载);
reader=新的随机访问文件
(“/sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq”、“r”);
load=reader.readLine();
freqs[3]=整数.parseInt(加载);
//我尝试过的for循环未能实现
/*RandomAccessFile reader=null;
对于(i=0;i

core0频率看起来正确,其余读数为0,再次感谢

它给了你一个“无效参数”在哪里?首先,你需要根访问权限来查看…/cpufreq/cpuinfo\u cur\u freq,你甚至可能无法获得写访问权限(你肯定不能)。不知道为什么您不能阅读cpu1、cpu2和cpu3目录。抱歉,不清楚。我用来查看文件的终端告诉我cat参数无效,不管是否有root访问权限,都是如此。我实际上不想写入文件,只是从中读取值。我从哪个文件中读到几乎不重要;cpuinfo更精确,但即使缩放也会导致任何更新?我好像连终端上的文件都看不懂。我的论点无效。我不需要根来读取缩放频率,但我仍然无法让它工作