Meminfo and cpuinfo in Android (2): use code to Read File Information
1. Introduction:
In the previous article, we introduced the meminfo and cpuinfo files. This article describes program routines and uses code to obtain their values.
Take memino as an example.
2. Code:
Public static List GetMeminfo (){
List MemInfoList = new ArrayList ();
Try {
BufferedReader reader = new BufferedReader (new InputStreamReader (new FileInputStream ("/proc/meminfo"), 1000 );
String load = null;
While (load = reader. readLine ())! = Null ){
Long size = 0l;
String [] toks = load. split (":");
String sizeBuf = toks [1]. trim ();
String [] sizeBufToks = sizeBuf. split ("");
Size = Long. parseLong (sizeBufToks [0]); // kb
MemInfoList. add (size );
}
Reader. close ();
Return memInfoList;
} Catch (IOException ex ){
Ex. printStackTrace ();
Return null;
}
}
Is it easy.