android file > create a new folder on SD card


android file.

how could you create a new folder on SD card,

please follow be code.

package com.powenko.Tutorial_sd_create_folder;

import java.io.File;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;

public class Tutorial_sd_create_folderActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        createDirIfNotExists("/sdcard/powenko_sd/");
    }
    
    public static boolean createDirIfNotExists(String path) {
        boolean ret = true;

        File file = new File(path);
     //   File file = new File(Environment.getExternalStorageDirectory(), path);
        if (!file.exists()) {
            if (!file.mkdirs()) {
                Log.e("TravellerLog :: ", "Problem creating Image folder");
                ret = false;
            }
        }
        return ret;
    }
}

remember, add user permission

   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    

Leave a Reply