Java tutorial
//package com.java2s; //License from project: Apache License import android.os.Environment; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; public class Main { public static void writeToPublicDirectory(String filename, byte[] data, String directory, String environmentDirectory) throws Exception { File publicDirectory = new File(Environment.getExternalStoragePublicDirectory(environmentDirectory), directory); boolean result = publicDirectory.mkdirs(); File targetFile = new File(publicDirectory, filename); FileOutputStream fileOutputStream = new FileOutputStream(targetFile); fileOutputStream.write(data); fileOutputStream.close(); } public static void writeToPublicDirectory(String filename, String string, String directory, String environmentDirectory) throws Exception { File publicDirectory = new File(Environment.getExternalStoragePublicDirectory(environmentDirectory), directory); boolean result = publicDirectory.mkdirs(); File file = new File(publicDirectory, filename); FileOutputStream fileOutputStream = new FileOutputStream(file); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream); outputStreamWriter.write(string); outputStreamWriter.close(); } }