Issue with creating a string output to a file accessible on the sdcard
<p>This is my first post here, and i should advise that my knowledge is at best limited!</p>

<p>I am trying to create an app for my android phone.</p>

<p>I need to eventually output values input by the user to a file, most probably a txt file, that can be retreived direct from the phone when connected via a usb cable.</p>

<p>However, I am struggling to understand how to achieve this.</p>

<p>From what I understand that I need to ensure the card is mounted,
To get the path,
and then use FileOpenStream(), with FileWriter 
to 'load' strings into the file (sorry not sure on the proper way to desribe that, or anythign else for that matter)</p>

<p>I have also allowed Permission for in the manifest to write to the sdcard. However, all the exmaples i can find seem to not relate to the sdcard. any advise, and or pointing to tutorials gratefully recieved.</p>

<p>my current code, is all over the place as i have confused myself to much, sorry.</p>

<pre><code>boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {
    // We can read and write the media    
    mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
    // We can only read the media   
    mExternalStorageAvailable = true;
    mExternalStorageWriteable = false;
} else {
    // Something else is wrong. It may be one of many other states, but all we need   
    //  to know is we can neither read nor write  
    mExternalStorageAvailable = mExternalStorageWriteable = false;
}

if (mExternalStorageAvailable == true &amp;&amp; 
        mExternalStorageAvailable == true) {
    //Environment.getExternalStorageDirectory()  gets root path to SD card
    // FileOutputStream to output somehow
    File path = Environment.getExternalStorageDirectory();
    OutputStream out = null;
    try {
        //File path = Environment.getExternalStorageDirectory();
        //FileOutputStream f = new FileOutputStream(new File(path + "/DCIM", "fileName"));

        out = new BufferedOutputStream(new FileOutputStream(file));

        OutputStreamWriter osw = new OutputStreamWriter(f);

        osw.write("test txt");
        osw.flush();// ensure that everything is really written out and close
        osw.close();
        Toast.makeText(getBaseContext(), "path = " + path, Toast.LENGTH_LONG).show();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Toast.makeText(getBaseContext(), "File not FOund", Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Toast.makeText(getBaseContext(), "IOException", Toast.LENGTH_LONG).show();
    }
}
</code></pre>

<p>EDIT:</p>

<p>Here is the XML File (hopefully), to see if the FileNotFound exception is be caused by it.</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.androidbook.epcsn"
  android:versionCode="1"
  android:versionName="1.0"&gt;
&lt;uses-sdk android:minSdkVersion="9" /&gt;
&lt;permission&gt;&lt;/permission&gt;

&lt;application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true" android:permission="android.permission.WRITE_EXTERNAL_STORAGE"&gt;
</code></pre>
