我试图通过替换文件中的3行来编辑build.prop文件。以下方法保留原始行并将新行复制到新文件。我需要更换线路而不是添加新线路。替换文件中的多行不工作
我已经更新了我的代码使用“否则,如果”图所示
/**Changing build.prop values here
* @throws IOException */
public void PropEdit() throws InterruptedException, IOException
{
String origFile = "data/data/vzw.versatile1.props/build.orig.prop";
String propFile = "data/data/vzw.versatile1.props/build.new.prop";
try {
suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
os.writeBytes("chmod 777 /data/data/vzw.versatile1.props/build.new.prop\n");
BufferedReader in = new BufferedReader(new FileReader(origFile));
PrintWriter out = new PrintWriter(new File(propFile));
String line;
String params [];
while ((line = in.readLine()) != null) {
params = line.split("=");
if
(params[0].equalsIgnoreCase("ro.product.device")) {
out.println(params[0] + "=" + "Maguro");
/**out.println(line); **/
out.flush();
} else
if
(params[0].equalsIgnoreCase("ro.product.name"))
{
out.println(params[0] + "=" + "yakju");
/**out.println(line); **/
out.flush();
} else if (params[0].equalsIgnoreCase("ro.product.model"))
{
out.println(params[0] + "=" + "Galaxy Nexus");
/**out.println(line); **/
out.flush();
}
out.println(line);
}
boolean successful;
{
out.close();
in.close();
os.flush();
os.close();
suProcess.waitFor();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "ERROR: " + e.getMessage(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
你用'params []'表示什么意思? – 2013-05-03 21:15:45
向我们展示迄今为止尝试的代码! – Smit 2013-05-03 21:16:32
@ Versatile1你的实现看起来不错,那么问题在哪里?如果你显示这两个文件和你的预期输出,可能会有所帮助。 – Smit 2013-05-03 21:43:18