Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; import android.content.Context; import android.widget.Toast; public class Main { private static File extDir = null; private static Toast curToast = null; private static Context curContext = null; private static final File createFile(String filename, String data) { File file = new File(extDir, filename); return createFile(file, data); } static final File createFile(File file, String data) { OutputStream os = null; try { os = new FileOutputStream(file); os.write(data.getBytes()); os.flush(); os.close(); return file; } catch (Exception e) { try { if (null != os) { os.close(); } } catch (Exception e2) { } toast("Cannot write the data to file " + file.getAbsolutePath() + ": " + e.getMessage()); } return null; } static final void toast(String mesg) { if (null != curToast) { curToast.cancel(); } curToast = Toast.makeText(curContext, mesg, Toast.LENGTH_SHORT); curToast.show(); } }