public class GetProp extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String file_proc = readFile();
TextView tv = (TextView)findViewById(R.id.tv);
tv.setText("Read File contents from SDCARD : \n" + file_proc);
}
public String readFile(){
BufferedReader rdr;
String proc = "";
String line;
int lineNumber = 0;
try {
rdr = new BufferedReader(new FileReader("/proc/cpuinfo"));
while ((line = rdr.readLine()) != null) {
lineNumber++;
Matcher matcher = Pattern.compile("Processor: (.*)").matcher(line);
if (matcher.find()) {
proc = matcher.group(1);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return proc;
}
}
我想从 /proc/cpuinfo txt 文件中打印一行,例如处理器:“RESULT”,其中 RESULT 是 matcher.group(1)。但是我的结果中没有文字,我的问题在哪里?