我正在尝试将文件写入/ 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();
}