title: Write to a Text File Resource in Android
body: <p>Does anyone know how to write to a text file in Android using a resource like:</p>
  
  <pre><code>R.raw.my_text_file
  </code></pre>
  
  <p>I'm just looking for something clean and simple. I've Googled around but the examples I found didn't work. I tried to code using the Android docs but couldn't wrap my head around it...</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I've used the Android docs to create this code. The logs print out "1" and "9" and the code skips everything in between and does nothing:</p>
  
  <pre><code>    try {
          String filename = "res/raw/my_text_file.txt";
          String string;
  
          Log.v(TAG, "1");
          FileOutputStream fos = openFileOutput(filename, Context.MODE_PRIVATE);
          Log.v(TAG, "2");
  
          for (int i = 0; i &lt; list.size(); i++) {
              Log.v(TAG, "3");
              try {
                  Log.v(TAG, "4");
                  string = i + " - " + list.get(i);
                  fos.write(string.getBytes());
              } catch (Exception e) {
                  Log.v(TAG, "5");
              }
              Log.v(TAG, "6");
          }
          Log.v(TAG, "7");
          fos.close();
          Log.v(TAG, "8");
      } catch (Exception e) {
  
      }
      Log.v(TAG, "9");
  </code></pre>