【发布时间】:2012-11-12 11:39:21
【问题描述】:
我想把下面函数的String(结果)转换成Integer值除以1000(khz -> mhz)
private String ReadCPUMhz()
{
ProcessBuilder cmd;
String result="";
try{
String[] args = {"/system/bin/cat", "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"};
cmd = new ProcessBuilder(args);
Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[1024];
while(in.read(re) != -1)
{
result = result + new String(re);
}
in.close();
} catch(IOException ex){
ex.printStackTrace();
}
result = result.replace("\n", "");
result = result.replace(" ", "");
return result;
}
这个返回给了我一个字符串,f.e. 192000(千赫兹)。 但我想要一个 mhz 值..
与:
int mhz = Integer.parseInt(result)
应用自行关闭..
如何将khz值转换为mhz?
没有 .replace 行我得到一个错误。 Logcat 说:" invalid int: "192000 " 并且在这个数字之后有很多特殊字符,比如菱形..
所以我不知道如何获得正确的价值..
你能帮帮我吗?
我认为结果值有问题。
谢谢
【问题讨论】:
标签: android parsing integer cpu