0

目标:读取我的根目录中的文件的内容。最终我希望能够读取 .conf 文件,但现在我正在使用 .txt 文件进行测试,因为它似乎更容易开始......

我正在使用 XDA 视频中的开源 Shell 文件导航到我的根目录。作为参考,该文件位于:“/data/misc/joke.txt”

这是我的主要方法中的代码:

            String command[]={"su","-c","ls /data/misc"};
            Shell shell = new Shell();
            String output = shell.sendShellCommand(command);

            try {
                read(output);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

所以基本上所做的就是授予 SU 权限,然后导航到 /data/misc 文件夹。然后在 Shell() 类中,我扫描每个文件并搜索我想要的文本文件。这可能是多余的,因为我希望文本文件每次都是“joke.txt”。无论如何,我对这段代码的 read() 方法有疑问:

    public void read(String out) throws Exception{

    File yourFile = new File("/data/misc", out);

    FileReader file = new FileReader(yourFile);
    BufferedReader reader = new BufferedReader(file);
    String line;
    String text = "";
    line = reader.readLine();

    while (line != null) {
        text += (line);
        line = reader.readLine();                       
    }

    setNewTextInTextView(text);
        }       

它在这一行崩溃:

    FileReader file = new FileReader(yourFile);

有小费吗?

4

0 回答 0