【发布时间】: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