title: Reading and Writing a file from SD card
body: <p>I have bought a book ("Beginning Android Games") by Mario Zechner. On page 149, he talks about saving and opening a file on External Storage. I understand the code, however I dont understand WHY it says this:</p>
  
  <p><img src="https://i.stack.imgur.com/oM7yS.png" alt="Screenshot of error"></p>
  
  <p>Why does it say this? I have all the permissions in my Manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.amzoft.android.reference"
  android:versionCode="1"
  android:versionName="1.0" 
  android:installLocation="preferExternal"&gt;
  
  &lt;application
      android:label="Android Reference"
      android:icon="@drawable/ic_launcher"
      android:debuggable="true"&gt;
      &lt;activity
          android:label="Android Reference"
          android:name=".AndroidReferenceActivity" 
          android:screenOrientation="portrait"
          android:configChanges="keyboard|keyboardHidden|orientation"&gt;
          &lt;intent-filter &gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity 
          android:label="LifeCycleTest"
          android:name=".LifeCycleTest"
          android:configChanges="keyboard|keyboardHidden|orientation"/&gt;
      &lt;activity 
          android:label="SingleTouchTest"
          android:name=".SingleTouchTest"
          android:configChanges="keyboard|keyboardHidden|orientation"/&gt;
      &lt;activity 
          android:label="MultiTouchTest"
          android:name=".MultiTouchTest"
          android:configChanges="keyboard|keyboardHidden|orientation"/&gt;
      &lt;activity 
          android:label="KeyTest"
          android:name=".KeyTest"
          android:configChanges="keyboard|keyboardHidden|orientation"/&gt;
       &lt;activity 
          android:label="AccelerometerTest"
          android:name=".AccelerometerTest"
          android:configChanges="keyboard|keyboardHidden|orientation"/&gt;
       &lt;activity 
          android:label="AssetsTest"
          android:name=".AssetsTest"
          android:configChanges="keyboard|keyboardHidden|orientation"/&gt;
       &lt;activity 
          android:label="ExternalStorageTest"
          android:name=".ExternalStorageTest"
          android:configChanges="keyboard|keyboardHidden|orientation"/&gt;
  &lt;/application&gt;
  &lt;uses-sdk android:minSdkVersion="8"  android:targetSdkVersion="10"/&gt;
  &lt;uses-permission android:name="android.permisson.WRITE_EXTERNAL_STORAGE" android:required="true"/&gt;
  &lt;uses-permission android:name="android.permission.WAKE_LOCK" android:required="false"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>And my code:</p>
  
  <pre><code>package com.amzoft.android.reference;
  
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.File;
  import java.io.FileReader;
  import java.io.FileWriter;
  import java.io.IOException;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.os.Environment;
  import android.widget.TextView;
  
  public class ExternalStorageTest extends Activity{
  
  @Override
  public void onCreate(Bundle saveInstanceState)
  {
      super.onCreate(saveInstanceState);
      TextView textView = new TextView(this);
      setContentView(textView);
  
      String state = Environment.getExternalStorageState();
      if(!state.equals(Environment.MEDIA_MOUNTED))
      {
          textView.setText("SD card is not mounted");
      }else{
          File externalDir = Environment.getExternalStorageDirectory();
          File textFile = new File(externalDir.getAbsolutePath() + File.separator + "text.txt");
  
          try{
              writeTextFile(textFile, "This is a test &gt;:0\nLINE BREAK");
              String text = readTextFile(textFile);
              textView.setText(text);
              if(!textFile.delete())
              {
                  textView.setText("Couldn't remove temporary directory,     sorry mate.");
              }
          }catch(Exception e){
              textView.setText(e.getMessage());
          }
      }   
  }
  
  private void writeTextFile(File file, String text) throws IOException
  {
      BufferedWriter writer = new BufferedWriter(new FileWriter(file));
      writer.write(text);
      writer.close();
  }
  
  private String readTextFile(File file) throws IOException
  {
      BufferedReader reader = new BufferedReader(new FileReader(file));
      StringBuilder text = new StringBuilder();
      String line;
      while((line = reader.readLine()) != null)
      {
          text.append(line);
          text.append("\n");//BECAUSE ITS A LINE :D
      }
      reader.close();
      return text.toString();
  }
  
  }
  </code></pre>
  
  <p>I hope someone can help me, because Im confused right now.</p>