如何在android中读取系统文件?

时间:2015-09-26 16:14:45

标签: android file system

我想从android的系统文件夹中读取“build.prop”文件,并将其作为字符串显示在textview中。但是,我的应用程序正在运行,然后强制关闭..

我的代码:

public void selfDestruct(View view) throws IOException {
    File path = getApplicationContext().getFilesDir();
    File file = new File(path, "build.prop");

    int length = (int) file.length();

    byte[] bytes = new byte[length];

    FileInputStream in = new FileInputStream(file);
    try {
        in.read(bytes);
    } finally {
        in.close();
    }

    String contents = new String(bytes);

    textView.setText(contents);
}

0 个答案:

没有答案