Java tutorial
//package com.java2s; import java.io.File; import java.util.Random; import android.content.ContentValues; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.os.Environment; import android.os.Process; public class Main { static File make_tmpdir(Context context, SQLiteDatabase db) throws Exception { File extdir = Environment.getExternalStorageDirectory(); File tmp_top = new File(extdir, "tmp_LongText"); if (!tmp_top.exists()) { if (!tmp_top.mkdir()) throw new Exception("cannot create directory: " + tmp_top.getPath()); } if (!tmp_top.canWrite()) throw new Exception("missing permission to write to " + tmp_top.getPath()); File tmpdir; Random r = new Random(); do { tmpdir = new File(tmp_top, String.format("%d", r.nextInt())); } while (tmpdir.exists()); if (!tmpdir.mkdir()) throw new Exception("cannot create directory: " + tmp_top.getPath()); if (!tmpdir.canWrite()) throw new Exception("missing permission to write to " + tmp_top.getPath()); ContentValues v = new ContentValues(); v.put("pid", Process.myPid()); v.put("tmpdir", tmpdir.getPath()); v.put("ctime", System.currentTimeMillis()); db.insert("tmpdir", null, v); return tmpdir; } }