3

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")
Jay Mayu
  • 17,023
  • 32
  • 114
  • 148

5 Answers5

8

Try like this:

String SD_CARD_PATH = Environment.getExternalStorageDirectory().toString();
new File(SD_CARD_PATH + "/" + "splah2.jpg");
jainal
  • 2,973
  • 2
  • 20
  • 18
  • OMG!!!! wot a shame, dat was a silly spelling mistake in file name :) thanks for saving my day :) – Jay Mayu Aug 18 '11 at 04:48
  • External storage doesn't always mean it's SD card. Some manufacturers reserve a space in the built-in internal storage which can acts as a "external storage". Read thoroughly the [official definition here](https://developer.android.com/guide/topics/data/data-storage.html#filesExternal) – mr5 Feb 20 '18 at 10:16
3

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

Rasel
  • 15,499
  • 6
  • 40
  • 50
Lior Ohana
  • 3,467
  • 4
  • 34
  • 49
0

try this,

File f=new File("/sdcard/splah2.jpg");
ilango j
  • 5,967
  • 2
  • 28
  • 25
0

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

Shash316
  • 2,218
  • 18
  • 19
0

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"