0

I'm trying to save strings to a text file in the external memory of the android device.

I call this method:

public void writeToFile(String name, String mevent)
{
    File path =
            Environment.getExternalStoragePublicDirectory
                    (
                            Environment.DIRECTORY_DOWNLOADS
                    );

    if(!path.exists())
    {
        path.mkdirs();
    }

    File myfile = new File(path, "config.txt");


    try
    {
        myfile.createNewFile();
        FileOutputStream fOut = new FileOutputStream(myfile);
        OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
        myOutWriter.append(name);
        myOutWriter.append(mevent);

        myOutWriter.close();

        fOut.flush();
        fOut.close();
    }
    catch (IOException e)
    {
        Log.e("Exception", "File write failed: " + e.toString());
    }
}

I call the above method from an OnActivityResult that waits for strings from another activity. The strings definitely return from the other activity, but the file isn't created. I have given the write permission to external memory.

Any ideas to what I am doing wrong?

0 Answers0