Jaya Mayu
Jaya Mayu

Reputation: 17257

Android: How to access a file in the SD Card

I'm trying to access the image on the SD card using below code but I"m getting File not found exception. Can someone tell me a correct way to acess the file???

new File("/mnt/sdcard/splah2.jpg")

Upvotes: 3

Views: 12584

Answers (5)

Abdullah Muhamad
Abdullah Muhamad

Reputation: 9

try

    new File("/sdcard/splah2.jpg")

or

    new File(Environment.getExternalStorageDirectory() + "/" + "splah2.jpg")

both are same if SD card is install because,

    Environment.getExternalStorageDirectory() returns "/sdcard"

Upvotes: 0

Shash316
Shash316

Reputation: 2218

The code below has worked for me.

String mRelativeFolderPath = "/DCIM/Camera/";  // i.e. SDCard/DCIM/Camera
String mBaseFolderPath = Environment.getExternalStorageDirectory().getAbsolutePath() + mRelativeFolderPath; 
String filePath = mBaseFolderPath  + "test.jpg";
File handle = new File(filePath);

Shash

Upvotes: 0

ilango j
ilango j

Reputation: 6037

try this,

File f=new File("/sdcard/splah2.jpg");

Upvotes: 0

jainal
jainal

Reputation: 3021

Try like this:

String SD_CARD_PATH = Environment.getExternalStorageDirectory().toString();
new File(SD_CARD_PATH + "/" + "splah2.jpg");

Upvotes: 8

Lior Ohana
Lior Ohana

Reputation: 3527

Try running: new File(Environment.getExternalStorageDirectory() + "/splah2.jpg")

Upvotes: 3

Related Questions