Issues with build.phonegap write to file

I've created an app with PG build that writes to the file system, so I'm certain it can be done and doesn't require a plugin. The main conspicuous difference I'm seeing in my code is that I'm explicitly setting the exclusive flag in the getFile options to false.

If you're testing with iOS another shot in the dark solution would be to check that you're setting your app id correctly in the config.xml

EDIT: In the app I mentioned, there file system writing code is here


Here's the Java method I'm using for writing to a file:

public void writeMyFile(String fileName, String data) throws IOException {

    File root = Environment.getExternalStorageDirectory();
    System.out.println(root);
    File gpxfile = new File(root, fileName);

    FileWriter writer = new FileWriter(gpxfile);
    String[][] recordvalue = new String[100][100];
    System.out.println("fetched value" + data);
    String[] line = data.split("#");

    // I had multiple lines of data, all split by the # symbol in a single string.
    System.out.println("row length "+line.length);

        for (int i=1; i<line.length; i++)
        {
            writer.append("#");
            recordvalue[i] = line[i].split(",");
            for(int j=0; j<recordvalue[i].length; j++) {
                System.out.println(recordvalue[i][j]);
                writer.append(recordvalue[i][j]);
                writer.append(",");
            }
            writer.append("\n");
        }

    Uri uri = Uri.fromFile(gpxfile);
    System.out.println(uri);

    writer.flush();
    writer.close();

    try {
        // Do something
    }
    catch (Exception e) {
        // If there is nothing that can send a text/html MIME type
        e.printStackTrace();
    }
}

The imports for the class/method are as follows:

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;

import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;

import com.phonegap.api.Plugin;

And the main execute class for the plugin is as follows:

public PluginResult execute(String arg0, JSONArray arg1, String arg2) {
    try {
         String fileName = arg1.getString(0);
         String data = arg1.getString(1);
         writeMyFile(fileName, data);
    }
    catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}