title: How to write a file inside system/etc/wifi/wpa_supplicant.conf file using android program?
body: <p>I am working on wifi related app, which takes the user giving username password and need to write(edit/append)in a file which is located in system/etc/wifi/ path.</p>
  
  <p>I searched in stackoverflow and got some answers and then tried but there is no luck. This is rooted device. I did remount and su too. I can able to read the same file. I placed all the permissions in manifest too. What I missed?</p>
  
  <pre><code>try {
      String[] command = new String[]{"/system/bin/ls", "-l",
              "/system/etc/wifi/wpa_supplicant.conf" };
      Process process = Runtime.getRuntime().exec(command);
      BufferedReader reader = new BufferedReader(
              new InputStreamReader(process.getInputStream()));
      int read;
  
      String output = "";
      String line;
      while ((line = reader.readLine()) != null) {
          output.concat(line + "\n");
          Log.w("myApp", "[[output]]:" + line);
      }
      reader.close();
      process.waitFor();
  
      String[] command2 = new String[]{"/system/etc/wifi/chmod", "777",
              "/system/etc/wifi/wpa_supplicant.conf" };
  
      Runtime rt = Runtime.getRuntime();
      Process p = rt.exec(new String[]{"/system/bin/sh", "-c", "echo \"12345678\" &gt; /system/etc/wifi/wpa_supplicant.conf"});
  
      File path= Environment.getDataDirectory();
      FileWriter fw = new FileWriter(new File("/system/etc/wifi/wpa_supplicant"));
      fw.write('9');
      fw.close();
  
      Log.d(TAG, "File Saved Successfully !!!");
  
      //display file saved message
          /*Toast.makeText(getBaseContext(), "File saved successfully!",
          Toast.LENGTH_SHORT).show();*/
  
  } catch (Exception e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>Here is my manifest permissions (outside application tag and some more permissions also there for some other purpose ). </p>
  
  <p></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/&gt;
  &lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/&gt;
  &lt;uses-permission android:name="android.permission.WRITE_SETTINGS"/&gt; 
  </code></pre>
  
  <p>And below error I am getting,</p>
  
  <pre><code>01-01 06:13:53.565: W/myApp(11205): [[output]]:-rw-rw-rw- root     root           58 2000-01-01 03:56 wpa_supplicant.conf
  01-01 06:13:53.580: W/System.err(11205): java.io.FileNotFoundException: /system/etc/wifi/wpa_supplicant: open failed: EROFS (Read-only file system)
  01-01 06:13:53.580: W/System.err(11205):    at libcore.io.IoBridge.open(IoBridge.java:452)
  01-01 06:13:53.580: W/System.err(11205):    at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:87)
  01-01 06:13:53.580: W/System.err(11205):    at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:72)
  01-01 06:13:53.581: W/System.err(11205):    at java.io.FileWriter.&lt;init&gt;(FileWriter.java:42)
  01-01 06:13:53.581: W/System.err(11205):    at com.intel.sunnypoint.headless.HeadlessService.WriteBtn(HeadlessService.java:450)
  01-01 06:13:53.581: W/System.err(11205):    at com.intel.sunnypoint.headless.HeadlessService.setupWifiAPConfig(HeadlessService.java:386)
  01-01 06:13:53.581: W/System.err(11205):    at com.intel.sunnypoint.headless.HeadlessService$HttpServiceThread$WiFiPageHandler.handle(HeadlessService.java:1094)
  01-01 06:13:53.581: W/System.err(11205):    at org.apache.http.protocol.HttpService.doService(HttpService.java:248)
  01-01 06:13:53.581: W/System.err(11205):    at org.apache.http.protocol.HttpService.handleRequest(HttpService.java:192)
  01-01 06:13:53.581: W/System.err(11205):    at com.intel.sunnypoint.headless.HeadlessService$HttpServiceThread.run(HeadlessService.java:663)
  01-01 06:13:53.581: W/System.err(11205): Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system)
  01-01 06:13:53.581: W/System.err(11205):    at libcore.io.Posix.open(Native Method)
  01-01 06:13:53.581: W/System.err(11205):    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
  01-01 06:13:53.582: W/System.err(11205):    at libcore.io.IoBridge.open(IoBridge.java:438)
  01-01 06:13:53.582: W/System.err(11205):    ... 9 more
  </code></pre>