title: Android: Write text to txt
body: <p>With the following code, I try to write to my sdcard:</p>
  
  <pre><code>public void writedata(String data) {
            //BufferedWriter out = null;
  
            System.out.println(data);
            try{
  
                FileOutputStream out = new FileOutputStream(new File("/sdcard/tsxt.txt"));
                out.write(data.getBytes());
                out.close();  
  
                  } catch (Exception e) { //fehlende Permission oder sd an pc gemountet}
                      System.out.println("CCCCCCCCCCCCCCCCCCCCCCCALSKDJLAK");
                  }
  
            }
  </code></pre>
  
  <p>The permission in the Manifest:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;  
  </code></pre>
  
  <p>But now, when I open the file, nothing is in there. Where´s the problem? I´m sure <code>data</code> has some value.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I get this message in the LogCat:</p>
  
  <pre><code>02-06 01:59:51.676: W/System.err(1197): java.io.FileNotFoundException: /storage/sdcard0/sdcard/tsxt.txt: open failed: ENOENT (No such file or directory)
  </code></pre>
  
  <p>I tried to create the file on the sdcard but still the same error. Is there a code that the File is created if it doesn´t exists?</p>