我想知道为什么在尝试使用 Marshmallow 通过真实设备上传文件时会出现此错误。您能否解释一下解决方案。
12-28 10:39:32.606: E/3(17552): Excption : java.io.FileNotFoundException: /storage/emulated/0/WoodenstreetD.doc: open failed: ENOENT (No such file or directory)
上周我一直被这个问题困扰,但仍然遇到同样的问题。 提前致谢。
最佳答案
此错误是由于路径错误引起的。您从 onActivityResult 获取的路径不正确。使用它来获取所选文件的路径。
public static String getRealPathFromUri(Context ctx, Uri uri) {
String[] filePathColumn = { MediaStore.Files.FileColumns.DATA };
Cursor cursor = ctx.getContentResolver().query(uri, filePathColumn,
null, null, null);
if (cursor != null) {
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
picturePath = cursor.getString(columnIndex);
Log.e("", "picturePath : " + picturePath);
cursor.close();
}
return picturePath;
}
picturePath 为您提供图像/文件的完整路径。
它对我有用。
关于Android 为什么会出现此错误 ENOENT (No such file or directory),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34487991/