Java tutorial
//package com.java2s; import android.os.Environment; import java.io.*; public class Main { public static String postsDir() { return new File(dataRootDirectory(0), "Posts").getAbsolutePath(); } public static String dataRootDirectory(int extNum) { File sdcard = Environment.getExternalStorageDirectory(); if (!sdcard.exists()) { sdcard = new File("/sdcard"); } if (sdcard.exists()) { File rd = new File(sdcard, "YaoTouWan"); if (extNum > 0) { rd = new File(rd.getAbsolutePath() + extNum); } if (!rd.exists()) { if (rd.mkdirs()) { return rd.getAbsolutePath(); } } else if (rd.isDirectory()) { return rd.getAbsolutePath(); } else { return dataRootDirectory(extNum + 1); } } else { // todo no /sdcard/ return null; } return sdcard.getAbsolutePath(); } }