Android 为什么会出现此错误 ENOENT (No such file or directory)

标签 android filenotfoundexception

我想知道为什么在尝试使用 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/

相关文章:

android - 在 android 中使用动态 Realm

android - 尝试保存首选项(根据官方 android 引用)会导致错误

java - 错误 :Execution failed for task

Android Things 如何连接蓝牙音箱

hadoop - 执行 spark 作业时出现 FileNotFoundException

java - 尝试在 Android 中将文件写入 sdcard 时出现 FileNotFoundException(权限被拒绝)

android - 在为 ActionBar 设置 apptheme 时,我得到了这个奇怪的错误 red color is private。那什么意识?

android - 从我的 Assets 文件夹访问我的 json 文件时遇到问题

java - Eclipse,无法读取Java类中的文本文件

java - 如何检测 Java 中的 ProcessBuilder 是否找不到要执行的文件?