需要读写 "/sys/devices/virtual/timed_output/vibrator/amp" 文件我可以正常读,但是不知道怎么写。代码如下:public static void writeValue(String filename, String value) {
//FileOutputStream fos = null;
DataOutputStream os = null;
try {
/*fos = new FileOutputStream(new File(filename), false);
fos.write(value.getBytes());
fos.flush();*/
Process p;
p = Runtime.getRuntime().exec("su");
os = new DataOutputStream(p.getOutputStream());
os.writeBytes(value + " > " + filename + "\n");
os.writeBytes("exit\n");
Log.w(TAG, value + " >> " + filename);
os.flush();
} catch (IOException e) {
Log.w(TAG, "Could not write to " + filename);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
Log.d(TAG, "Could not close " + filename, e);
}
}
}
}我得到** Log.w(TAG, "Could not write to " + filename); **的返回值。不知道应该怎么写入?需要什么许可么?要不要全部重建来匹配root访问?
4 回答
临摹微笑
TA贡献1982条经验 获得超2个赞
os.writeBytes(value + " > " + filename + "\n");
这句不对
试试:
os.writeBytes("echo '"+value + "' > " + filename + "\n");或者:
os.writeBytes("echo -n '"+value + "' > " + filename + "\n");添加回答
举报
0/150
提交
取消
