我正在尝试将文件写入/ dev并且代码如下所示我在日志中出错。我做错了什么..我正在使用模拟器来测试这个...应该在实际设备?
try {
process = Runtime.getRuntime().exec("su");
OutputStream os = process.getOutputStream();
DataOutputStream dos = new DataOutputStream(os);
String cmd = "echo 'hello world'> /dev/pttycmd1";
String cmd1 = "echo 'hello world2'> /dev/pttycmd2";
dos.writeBytes(cmd);
dos.writeBytes(cmd1);
dos.flush();
File f = new File("/dev/pttycmd1");
if(f.exists())
{
/* do something */
Log.d("success", "File exists");
}
else
{
Log.d("error", "File does not exists");
//file.mkdirs();
//And your other stuffs goes here
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
答案 0 :(得分:1)
/dev
无法从普通用户写入。可能root
无法在/dev