我正在尝试从android文件系统中的/ dev / test节点读写数据。 我试过了
mount -o rw remount /dev && touch /dev/test
从shell开始工作,但是当我尝试使用
时Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("su");
proc = rt.exec("mount -o rw remount /dev && touch /dev/test");
/ dev /
下没有名为test的文件答案 0 :(得分:0)
尝试使用此方法执行:
private boolean performScript(String script) {
script = "mount -o rw remount /dev && touch /dev/test";
try {
// Executes the command.
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes(script + "\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
// // Reads stdout.
// // NOTE: You can write to stdin of the command using process.getOutputStream().
// final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
// int read;
// final char[] buffer = new char[4096];
// while ((read = reader.read(buffer)) > 0) {
// stringBuilder.append(buffer, 0, read);
// txtInfo.setText(stringBuilder.toString());
// }
// reader.close();
// Waits for the command to finish.
process.waitFor();
}
catch (IOException e) {
e.printStackTrace();
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
这里的技巧是将脚本作为超级用户运行。