如何在有根的Android手机中阅读存储在内部目录中的文件内容?
我正在使用以下但是它无效,我变得空白:
filePath = "/data/";
File file = new File(filePath, "test.conf");
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
}
catch (IOException e) {
}
return text.toString();
知道问题是什么吗?
答案 0 :(得分:0)
使用@ Blade0rz给出的链接中的示例,我修改了它以从内部存储器获取文件。基本上,我将内容复制到SD卡上的测试文件中。然后,我可以用它做任何事情,之后不需要root访问。
Process p;
try {
// Preform su to get root privledges
p = Runtime.getRuntime().exec("su");
// Attempt to write a file to a root-only
DataOutputStream os = new DataOutputStream(p.getOutputStream());
String path = Environment.getExternalStorageDirectory().getPath() + "/test.txt";
os.writeBytes("cat /data/test.conf >" + path +"\n");
// Close the terminal
os.writeBytes("exit\n");
os.flush();
Toast.makeText(getApplicationContext(), path, Toast.LENGTH_LONG).show();
try {
p.waitFor();
if (p.exitValue() != 255) {
// TODO Code to run on success
Toast.makeText(getApplicationContext(), "Phone is Rooted.", Toast.LENGTH_LONG).show();
}
else {
// TODO Code to run on unsuccessful
Toast.makeText(getApplicationContext(), "Phone is Not Rooted.", Toast.LENGTH_LONG).show();
}
} catch (InterruptedException e) {
// TODO Code to run in interrupted exception
Toast.makeText(getApplicationContext(), "Phone is Not Rooted.", Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
// TODO Code to run in input/output exception
Toast.makeText(getApplicationContext(), "Phone is Not Rooted.", Toast.LENGTH_LONG).show();
}