1

我需要构建一个应用程序,使我能够使用自己的应用程序编辑 build.prop。这是为了优化 build.prop 中的一些值。当然,我可以使用具有 root 访问权限的文件管理器来编辑此文件。但我的问题是,我需要使用我创建的应用程序来编辑它,并让新手用户可以轻松地使用我的应用程序推荐的设置来编辑文件。请帮我弄清楚这一点。谢谢你的时间!

4

1 回答 1

3

像这样的东西应该工作。代码尚未经过测试,可能需要进行一些更改

请求超级用户访问

process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes("mount -o remount rw /system/\n"); 
os.writeBytes("exit\n");
os.flush();
process.waitFor();

File file=new File("/system/build.prop");

读取文件

FileInputStream fis = openFileInput("/system/build.prop");
String content = "";
byte[] input = new byte[fis.available()];
while (fis.read(input) != -1) {}
content += new String(input);

在这里编辑String content

写文件

DataOutputStream outstream= new DataOutputStream(new FileOutputStream(file,false));
String body = content;
outstream.write(body.getBytes());
outstream.close();

请记住备份您的 build.prop,以防在编辑过程中出现问题。

于 2012-07-15T07:39:57.373 回答