我正在尝试使用以下代码访问SD卡上的图像,但我发现文件未找到异常。有人可以告诉我一个正确的方法来访问该文件???
new File("/mnt/sdcard/splah2.jpg")
答案 0 :(得分:8)
试试这样:
String SD_CARD_PATH = Environment.getExternalStorageDirectory().toString();
new File(SD_CARD_PATH + "/" + "splah2.jpg");
答案 1 :(得分:3)
尝试运行:new File(Environment.getExternalStorageDirectory() + "/splah2.jpg")
答案 2 :(得分:0)
试试这个,
File f=new File("/sdcard/splah2.jpg");
答案 3 :(得分:0)
以下代码对我有用。
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
答案 4 :(得分:0)
尝试
new File("/sdcard/splah2.jpg")
或
new File(Environment.getExternalStorageDirectory() + "/" + "splah2.jpg")
如果安装SD卡,两者都相同,
Environment.getExternalStorageDirectory() returns "/sdcard"