I found a amazing problem in downloading image.
The url of image is http://www.xbiquge.la/files/article/image/50/50353/50353s.jpg
I can open and save it in the chrome.but when I download it by the code,it fail.
I can't open it by the imageviewer.
Note:The size of wrong image is less than the right image file's.And other image of other website is ok.
I don't know what happen.Please help,Thanks advance
Following is my code
val imgUrl = "http://www.xbiquge.la/files/article/image/50/50353/50353s.jpg"
val conn = URL(imgUrl).openConnection()
val bytes = conn.getInputStream().readBytes()
File("D:\\test.jpg").writeBytes(bytes)
I also try to use java to download the image.it's also failure...
URL url = new URL("http://www.xbiquge.la/files/article/image/50/50353/50353s.jpg");
URLConnection connection=url.openConnection();
InputStream inputStream = connection.getInputStream();
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File("d:\\download.jpg")));
int c;
byte[] temp = new byte[1024 * 2];
while ((c = bufferedInputStream.read(temp)) != -1) {
bufferedOutputStream.write(temp,0,c);
}
bufferedOutputStream.close();
inputStream.close();