Note that there are some explanatory texts on larger screens.

plurals
  1. POFiles copy line instead of replace line
    primarykey
    data
    text
    <p>I'm trying to edit the build.prop file by replacing 3 lines in the file. The following method leaves the original lines and copies the new ones to the new file. I need to replace the lines instead of adding new lines to it. The origFile is pulled from system and a backup is created the following is a portion of the output file.</p> <pre><code>ro.product.model=Galaxy Nexus ro.product.model=SCH-I605 ro.product.brand=samsung ro.product.name=yakju ro.product.name=t0ltevzw ro.product.device=Maguro ro.product.device=t0ltecdma </code></pre> <p>I've updated my code to use the "else if" shown below</p> <pre><code>public void PropEdit() throws InterruptedException,IOException { String origFile="data/data/app.props/build.orig.prop"; String propFile="data/data/app.props/build.new.prop"; try{ suProcess=Runtime.getRuntime().exec("su"); DataOutputStream os=new DataOutputStream(suProcess.getOutputStream()); os.writeBytes("chmod 777 /data/data/app.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(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload