How to store data to SD card?

I found a couple of threads about data on SD cards on Android devices (this and this), but I haven’t found how to store data to one.
I’d like to be able to store simple text files from my app to the SD card. What function should I call to do that?
Thanks

I searched a bit and found this thread, where according to Rancs, this code creates a file called “example.txt” in the SD card, specifically here /sdcard/Android/data/com.mycom.myapp

ofBuffer dataBuffer;
    dataBuffer.append("Some text for testing..");
    ofFile file;
    file.open(ofToDataPath("") + "example.txt", ofFile::ReadWrite, false);
    file.writeFromBuffer(dataBuffer);

I tried it and the file is actually created in the Internal storage/Android/data/cc.openframeworks.appName/files (which is preferable actually, so no external SD card is needed).
What’s weird is that if I change the file name nothing is written. Also, if I try to create a directory (actually that would be optimal as I would like all saved files to be in one place without other files), by writing this:

file.open(ofToDataPath("") + "/savedPatches/example.txt", ofFile::ReadWrite, false);

the directory “savedPatches” is created, but no file is created inside there.
Any hints?

Ok, got it. Have to use the following instead, for writing:

bool fileWritten = ofBufferToFile(ofToDataPath("") + "/filedirectory/filename.txt", dataBuffer);

This will create a directory called “filedirectory” in /Internal storage/Android/data/cc.openframeworks.appName/files and it will create a file called “filename.txt” in that directory. To read it call:

ofBuffer buffer = ofBufferFromFile(ofToDataPath("") + "/filedirectory/filename.txt");

Then you can use the loadTextFileExample in examples/input_output from the OF examples found in the main OSes distributions (got it from the Linux distro). Hope this helps other people too.