【问题标题】:Error saving image file: No such file or directory保存图像文件时出错:没有这样的文件或目录
【发布时间】:2015-08-06 15:53:51
【问题描述】:

我在下载图片时遇到以下错误:

Error saving image file: /storage/emulated/0/InstagramFavouriteshttps:/scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s320x320/e15/11371164_841887855880940_277042645_n.jpg: open failed: ENOENT (No such file or directory)

下面是我的代码:

private boolean storeImage(Bitmap imageData, String filename) {
        //get path to external storage (SD card)
       //String iconsStoragePath = Environment.getExternalStorageDirectory() + "/myAppDir/myImages/"

        File newfile = new File(rootPath);
        //create storage directories, if they don't exist
        //rootFileDirectory.mkdirs();
        System.out.println("IMAGES DOWNLOADED IN FOLDER=="+newfile);
        try {
            String filePath = newfile.toString() + filename;
            FileOutputStream fileOutputStream = new FileOutputStream(filePath);

            BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);

            //choose another format if PNG doesn't suit you
            imageData.compress(CompressFormat.PNG, 100, bos);

            bos.flush();
            bos.close();

        } catch (FileNotFoundException e) {
            Log.w("TAG", "Error saving image file: " + e.getMessage());
            return false;
        } catch (IOException e) {
            Log.w("TAG", "Error saving image file: " + e.getMessage());
            return false;
        }

        return true;
    }

【问题讨论】:

  • 问题似乎与保存路径包含http://..../filename.png 而不仅仅是/filename.png这一事实有关

标签: android image download server


【解决方案1】:

在清单中添加此权限。

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

编辑:

您需要在该行下方为新文件分配最终路径

filePath = newfile.toString() + filename;

你应该添加:

newfile = new File(filePath);

【讨论】:

  • 我正在使用这个权限
猜你喜欢
  • 2013-07-03
  • 2013-01-14
  • 2014-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-04
相关资源
最近更新 更多