gpt4 book ai didi

java - android 在/dev 中写入文件

转载 作者:行者123 更新时间:2023-12-01 14:36:21 24 4
gpt4 key购买 nike

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

最佳答案

普通用户无法写入

/dev。可能 root 都无法在 /dev

上写入内容

关于java - android 在/dev 中写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16457915/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com