微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java.io.FileNotFoundException:文件:/storage/emulated/0/WhatsApp/Media/.Statuses/xyz.jpg:打开失败:ENOENT无此类文件或目录

如何解决java.io.FileNotFoundException:文件:/storage/emulated/0/WhatsApp/Media/.Statuses/xyz.jpg:打开失败:ENOENT无此类文件或目录

我想将所有文件从/WhatsApp/.Statuses/复制到新文件夹,但是我遇到了这个问题,

java.io.FileNotFoundException:文件:/storage/emulated/0/WhatsApp/Media/.Statuses/7cf30a37ee9341508b467ff2d9a361bc.jpg:打开失败:ENOENT(没有这样的文件或目录)

我的代码在这里

private View.OnClickListener downloadMediaItem(Story files) {
    return new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new Runnable() {

                @Override
                public void run() {
                    try {
                        checkFolder();
                        String sourcePath = String.valueOf(files.getUri());
                        copyFile(sourcePath,new File(Environment.getExternalStorageDirectory().toString() + Constant.SAVE_FOLDER_NAME));
                        Toast.makeText(context,"Saved!",Toast.LENGTH_SHORT).show();
                    } catch (Exception e) {
                        e.printstacktrace();
                        Log.e("RecyclerV","onClick: Error:" + e.getMessage());
                    }
                }
            }.run();
        }
    };
}

private void copyFile(String sourcePath,File file) throws IOException {
    if (!file.getParentFile().exists())
        file.getParentFile().mkdirs();

    if (!file.exists()) {
        file.createNewFile();
    }

    FileChannel source = null;
    FileChannel destination = null;

    try {
        source = new FileInputStream(String.valueOf(sourcePath)).getChannel();
        destination = new FileOutputStream(file).getChannel();
        destination.transferFrom(source,source.size());
    } finally {
        if (source != null) {
            source.close();
        }
        if (destination != null) {
            destination.close();
        }
    }
}

我该如何解决这个问题?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。