title: Android - Save to a text file
body: <p>I am trying to write text to a file but i cant seem to get it to work. </p>
  
  <pre><code>public static void saveState(){
  
          String data = age + "," ;
          FileOutputStream fos;
          Context con = getApplicationContext();
          try {
              fos = con.openFileOutput("state", 0);
              OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fos);
              outputStreamWriter.write(data);
              outputStreamWriter.close();
          }
          catch (IOException e) {
              Log.e("Exception", "File write failed: " + e.toString());
          } 
  
  
      }
  </code></pre>
  
  <p>I have looked around and it seems i cant call openFileOutput() with out the context but have no idea "Context con = getApplicationContext()" will not work as im outside of a Activity. it just tells me that getapplicationcontext is undefined for the type. Can anyone help me out here?</p>