android获取CPU参数(命令行方式)
16lz
2021-01-23
public static String fetch_cpu_info() {
String result = null;
try {
String[ ] args = { "/system/bin/cat", "/proc/cpuinfo" };
result = run(args, "/system/bin/");
Log.i("result","result=" + result);
} catch (IOException ex) {
ex.printStackTrace();
}
return result;
}
public synchronized static String run ( String [] cmd,String workdirectory)
throws IOException {
String result = "";
try {
ProcessBuilder builder = new ProcessBuilder ( cmd );
//设置一个路径
if ( workdirectory != null )
builder.directory ( new File ( workdirectory ) ) ;
builder.redirectErrorStream (true) ;
Process process = builder.start ( ) ;
InputStream in = process.getInputStream ( ) ;
byte[] re = new byte[1024] ;
while (in.read(re) != -1){
result = result + new String (re) ;
}
in.close ( ) ;
} catch ( Exception ex ) {
ex.printStackTrace ( ) ;
}
return result ;
}
String result = null;
try {
String[ ] args = { "/system/bin/cat", "/proc/cpuinfo" };
result = run(args, "/system/bin/");
Log.i("result","result=" + result);
} catch (IOException ex) {
ex.printStackTrace();
}
return result;
}
public synchronized static String run ( String [] cmd,String workdirectory)
throws IOException {
String result = "";
try {
ProcessBuilder builder = new ProcessBuilder ( cmd );
//设置一个路径
if ( workdirectory != null )
builder.directory ( new File ( workdirectory ) ) ;
builder.redirectErrorStream (true) ;
Process process = builder.start ( ) ;
InputStream in = process.getInputStream ( ) ;
byte[] re = new byte[1024] ;
while (in.read(re) != -1){
result = result + new String (re) ;
}
in.close ( ) ;
} catch ( Exception ex ) {
ex.printStackTrace ( ) ;
}
return result ;
}
更多相关文章
- Android 7.0调用相机拍照并获取图片路径
- android加载文件的方式,路径的写法
- android的路径问题
- Android Studio 中如何更改SDK路径
- Android 获取assets的绝对路径
- Android 获取路径
- Android将获取到文件的uri转换为字符串的路径