Image is partially downloading,

I cannot download the file in following url:

Only a part of the file is being downloaded.

Following is my code. Please let me know if I'm doing anything wrong.

URLConnection urlConn = new URL( "").openConnection(); InputStream is = urlConn.getInputStream(); FileOutputStream fos = new FileOutputStream( file.getPath() ); byte[] buffer = new byte[4096]; int len; while( ( len = buffer ) ) > 0 ) { fos.write( buffer, 0, len ); } fos.close();

-------------Problems Reply------------

I just tried this...

HttpClient client = HttpClientBuilder.create().build();
HttpGet get = new HttpGet("");

HttpResponse execution = client.execute(get);
HttpEntity entity = execution.getEntity();
FileOutputStream outputStream = new FileOutputStream("C:\\tmp\\imgout.jpg");

if (entity != null) {
InputStream inputStream = entity.getContent();
IOUtils.copy(inputStream, outputStream);


...and the output file contains the TEXT...

<META NAME="robots" CONTENT="noindex">
Sorry, your browser doesn't seem to support frames! <br>
Proceed to <A href=""></A> manually.

So probably nothing wrong with your code (I'd still use != -1 instead of > 0 though)! Maybe you need to set a request header or something...

Category:java Views:1 Time:2017-09-11

Related post

Copyright (C), All Rights Reserved.

processed in 0.086 (s). 10 q(s)