You need to check the permission:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Here is an example that saves a text file on the device.
public void generateNoteOnSD(Context context, String sFileName, String sBody) {
try {
File root = new File(Environment.getExternalStorageDirectory(), "Notes");
if (!root.exists()) {
root.mkdirs();
}
File gpxfile = new File(root, sFileName);
FileWriter writer = new FileWriter(gpxfile);
writer.append(sBody);
writer.flush();
writer.close();
Toast.makeText(context, "Saved", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}
Just call it, like this:
generateNoteOnSD(this, "nome_do_arquivo", "texto_do_arquivo");