title: Android: Write to file in a non-Activity class
body: <p>How do I open and write to a file in an Android class outside an activity?</p>
  
  <p><code>FileWriter</code> is my external class, initialized from <code>MainActivity</code>. The following line in <code>FileWriter</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>FileOutputStream fos = openFileOutput("filename", Context.MODE_PRIVATE);
  </code></pre>
  
  <p>Yields this compilation error:</p>
  
  <pre><code>The method openFileOutput(String, int) is undefined for the type FileWriter
  </code></pre>
  
  <p>I guess that the class requires some application context - how do I pass it?</p>