简体   繁体   English

Android:打开失败:ENOENT没有这样的文件或目录

[英]Android: open failed: ENOENT No such file or directory

I know have many question like my question. 我知道有很多问题,例如我的问题。 But It is different. 但这是不同的。 I copy file from folder A to folder B in EXTERNAL_STORAGE use mothod below: 我使用下面的方法将文件从文件夹A复制到EXTERNAL_STORAGE文件夹B:

    public static String copyFile(String path) {
        String fileToName = String.valueOf(System.currentTimeMillis());

        File pathFrom = new File(path);
        File pathTo = new File(Environment.getExternalStorageDirectory() + "/.noname");
        File file = new File(pathTo, fileToName + ".bak");

        while (file.exists()) {
            fileToName = String.valueOf(System.currentTimeMillis());
            file = new File(pathTo, fileToName + ".bak");
        }

        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(pathFrom);
            out = new FileOutputStream(file);

            byte[] data = new byte[in.available()];
            in.read(data);
            out.write(data);
            in.close();
            out.close();

        } catch (FileNotFoundException e) {
            Log.e(TAG, e.getMessage());
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
        }
        return file.getPath();
    }

The path param is: "/storage/emulated/0/Download/image_preview.jpg". 路径参数为:“ / storage / emulated / 0 / Download / image_preview.jpg”。 When execute this method I got an error: /storage/emulated/0/Download/tree_leaves_sunlight.jpg: open failed: ENOENT (No such file or directory) . 执行此方法时,出现错误: /storage/emulated/0/Download/tree_leaves_sunlight.jpg: open failed: ENOENT (No such file or directory) Folder .noname have exists. 文件夹.noname存在。 Is there any suggestion for my problem? 对我的问题有什么建议吗?

**UPDATE: This file I opening with ImageView . **更新:我使用ImageView打开此文件。 When I not open I can copy. 当我不打开时,我可以复制。 But When I opening I got this error. 但是当我打开我得到这个错误。 PS: I preview the image in ImageView . PS:我在ImageView预览图像。 And there have a Button copy image. 并有一个Button复制图像。 When click to Button execute method copy this image to other folder. 当单击“按钮”执行方法时,将此图像复制到其他文件夹。

When you create the File object for the parent directory File pathTo = new File(Environment.getExternalStorageDirectory() + "/.noname") Don't forget to actually create this folder 为父目录创建File对象时File pathTo = new File(Environment.getExternalStorageDirectory() + "/.noname")不要忘记实际创建此文件夹

 pathTo.mkdirs();

Also try to open file you're trying to copy in the gallery. 另外,尝试打开您要在图库中复制的文件。 It can be damaged and Android just can't open it. 它可能会损坏,而Android无法打开它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android 6-打开失败:ENOENT(无此类文件或目录) - android 6 - open failed: ENOENT (No such file or directory) Android:打开失败:ENOENT(无此类文件或目录)错误 - Android: open failed: ENOENT (No such file or directory) Error Android 模拟器打开失败:ENOENT(没有那个文件或目录) - Android emulator open failed: ENOENT (No such file or directory) Android:打开失败:ENOENT(没有这样的文件或目录) - Android: open failed: ENOENT (No such file or directory) Android 10 打开失败:ENOENT(没有这样的文件或目录) - Android 10 open failed: ENOENT (No such file or directory) Android解压缩失败:ENOENT(无此文件或目录) - Android unzip open failed: ENOENT (No such file or directory) Android Mp3文件-打开失败:ENOENT(无此文件或目录) - Android Mp3 File - open failed: ENOENT (No such file or directory) Android XML:打开失败:ENOENT(没有这样的文件或目录),DOMParser - Android XML: open failed: ENOENT (No such file or directory) , DOMParser Android:NDK:超级打开失败:ENOENT(没有这样的文件或目录)错误 - Android : NDK : Superpowered Open failed: ENOENT (No such file or directory) Error 写入存储打开失败时出错:android 中的 ENOENT (No such file or directory) - Error while writing storage open failed: ENOENT (No such file or directory) in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM