Android cat命令返回空

时间:2018-11-26 10:00:50

标签: java android shell

使用cat命令运行getRuntime()。exec()时遇到问题。 代码返回空结果。 代码在这里

try {

        Process process = Runtime.getRuntime().exec(" cat /data/.num");

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(process.getInputStream()));
        int read;
        char[] buffer = new char[4096];
        StringBuffer output = new StringBuffer();
        while ((read = reader.read(buffer)) > 0) {
            output.append(buffer, 0, read);
        }
        reader.close();

        // Waits for the command to finish.
        process.waitFor();

        sharedPref.edit().putString("NUMBER",output.toString()).apply();


    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }

但是当我从终端(adb shell)运行此命令时,它将返回正确的结果

enter image description here

有人可以帮忙吗?

0 个答案:

没有答案
相关问题