0
我是一名新手Android开发人员。我已经使用通用图像加载器加载了一个图像,我想将它保存在我的SD卡上。该文件是在所需的目录中创建的,文件名正确,但文件大小始终为0.我做错了什么?使用Android通用图像加载器将图像保存为当前视图到SD卡
一个相关的片段如下:
PS:图像已经存在于磁盘,它没有被从互联网上下载。
private void saveImage(String imageUrls2, String de) {
String filepath = Environment.getExternalStorageDirectory()
.getAbsolutePath();
File SDCardRoot = Environment.getExternalStorageDirectory()
.getAbsoluteFile();
String filename = de;
File myDir = new File(SDCardRoot+"/testdir");
Bitmap mSaveBit = imageLoader.getMemoryCache();
File imageFile = null;
try {
//create our directory if it does'nt exist
if (!myDir.exists())
myDir.mkdirs();
File file = new File(myDir, filename);
if (file.exists())
file.delete();
FileOutputStream fileOutputStream = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
bos.flush();
bos.close();
} catch (IOException e) {
filepath = null;
e.printStackTrace();
Toast.makeText(getApplicationContext(),
R.string.diskful_error_message, Toast.LENGTH_LONG)
.show();
}
Log.i("filepath:", " " + filepath);
}
[从android通用图像加载器下载图像流]的可能重复(http://stackoverflow.com/questions/13855166/download-image-stream-from-android-universal-image-loader) – Emmanuel