Android 读取根安卓手机内部目录中的文件

Android 读取根安卓手机内部目录中的文件,android,Android,如何读取根安卓手机内部目录中存储的文件内容 我正在使用以下内容,但它不起作用,我正在变为空白: filePath = "/data/"; File file = new File(filePath, "test.conf"); StringBuilder text = new StringBuilder(); try { BufferedReader br = new BufferedReader(new FileReader(file)); while

如何读取根安卓手机内部目录中存储的文件内容

我正在使用以下内容,但它不起作用,我正在变为空白:

    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(); 

知道有什么问题吗

使用@Blade0rz提供的链接中的示例,我对其进行了修改,以从内存中获取一个文件。基本上,我是将内容复制到SD卡上的测试文件中。随后,我可以用它做任何事情,之后就不需要根访问了

           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();
           }

您是否已请求并允许根权限?但它是否已根权限?我只检查我是否可以“su”,然后是否可以读取该文件。您的手机可能已根目录,但您的进程仍需要请求超级用户权限。看看这篇关于如何做到这一点的博文:你最好把你得到的错误发出来!