[英]Read-Write data from /dev/test file in android root file system in rooted device from android app
I am trying to read-write data from /dev/test node in android file system. 我正在尝试从android文件系统中的/ dev / test节点读写数据。 I tried
我试过了
mount -o rw remount /dev && touch /dev/test
from shell and it worked, but when I try to use 从外壳,它的工作,但当我尝试使用
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("su");
proc = rt.exec("mount -o rw remount /dev && touch /dev/test");
There is no file called test under /dev/ / dev /下没有名为test的文件
Try to exec it using this method: 尝试使用以下方法执行它:
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();
}
}
the trick here is to run the script being a superuser. 这里的技巧是以超级用户身份运行脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.