【发布时间】:2014-05-08 03:02:20
【问题描述】:
我是一名新手 Android 开发人员。我已经使用 Universal-image-loader 加载了一个图像,我想将它保存在我的 SD 卡上。该文件以正确的文件名在所需目录中创建,但其大小始终为 0。我做错了什么?
一个相关的sn-p如下:
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 universal-image-loader