使用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)运行此命令时,它将返回正确的结果
有人可以帮忙吗?