【发布时间】:2015-03-09 05:15:49
【问题描述】:
我正在使用 loopj 库 https://github.com/loopj/android-async-http 通过 URL 下载图像。作为回应,我将图像作为文件对象。我想将此图像作为 .jpg 存储到我的内部存储中并获取该图像的路径。有人可以帮我解决这个问题吗?或者向我推荐任何其他库或可以实现此功能的代码?
【问题讨论】:
标签: android android-file loopj
我正在使用 loopj 库 https://github.com/loopj/android-async-http 通过 URL 下载图像。作为回应,我将图像作为文件对象。我想将此图像作为 .jpg 存储到我的内部存储中并获取该图像的路径。有人可以帮我解决这个问题吗?或者向我推荐任何其他库或可以实现此功能的代码?
【问题讨论】:
标签: android android-file loopj
试试:
try {
File imgFile = null; //File you received from loopj
FileInputStream fis = new FileInputStream(imgFile);
FileOutputStream fos = new FileOutputStream(
new File("yourPath.jpg"));
byte fileContent[] = new byte[(int) imgFile.length()];
fis.read(fileContent);
fos.write(fileContent);
fis.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
【讨论】: