0

I have problem with run getRuntime().exec() with cat command. The code returns empty result. The code is here

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

but when I run this command from terminal (adb shell) it returns correct result

enter image description here

Can someone help?

user1214083
  • 122
  • 6

0 Answers0