Android: How to access a file in the SD Card

点点圈 提交于 2019-11-29 08:13:14

Try like this:

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

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

try this,

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

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

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"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!