【发布时间】:2016-08-06 04:53:31
【问题描述】:
请,需要帮助。我在将其保存到我的内部存储时遇到此错误 java.io.FileNotFoundException: http://news.yandex.ru/quotes/1507.png (可以通过浏览器看到)。 这是我的方法:
无效下载图(字符串链接){ 试试 {
URL url = new URL(link);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
File dbDirectory = new File(mctx.getFilesDir().getAbsolutePath()+ File.separator+"yqimages/");
if(!dbDirectory.exists())dbDirectory.mkdir();
String fname=link.substring(link.lastIndexOf("/")+1,link.length());
File file = new File(dbDirectory, fname);
FileOutputStream fileOutput = new FileOutputStream(file);
InputStream inputStream = urlConnection.getInputStream();
byte[] buffer = new byte[1024];
int bufferLength;
while ( (bufferLength = inputStream.read(buffer)) > 0 ) {
fileOutput.write(buffer, 0, bufferLength);
}
fileOutput.close();
} catch (final Exception e) {
e.printStackTrace();
}
}
你能写一个方法来下载\保存这个特定的图像(如上所示)吗?任何帮助表示赞赏! 得到它!!问题不在于代码,而在于图像https://news.yandex.ru/quotes/1507.png。由于某种原因,这张图片无法保存,而其他图片则无法保存。和“httpS://”有关系吗?
【问题讨论】:
-
好的,你正在使用 android - 应该在标签中指定,不要浪费我们的时间
标签: java android image save fileoutputstream