android file > create a new folder on SD card

June 18, 2012   ·   0 Comments

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" />
    
shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Android7

Amazon

adsbygoogle

Recent Posts

Categories

Amazon