Thursday, April 24, 2014

Andrews incomplete download files, the file is 1.88M, only 4.25K download


 HttpClient client = new DefaultHttpClient (); 
HttpGet get = new HttpGet (url);
HttpResponse response;
try {
response = client.execute (get);
HttpEntity entity = response.getEntity ();
long length = entity.getContentLength ();
Log.isLoggable ("DownTag", (int) length);
InputStream is = entity.getContent ();
FileOutputStream fileOutputStream = null;

if (is == null) {
throw new RuntimeException ("isStream is null");
}
File file = new File (Environment.getExternalStorageDirectory (), appName);
fileOutputStream = new FileOutputStream (file);
byte [] buf = new byte [10 * 1024];
int ch = -1;
do {
ch = is.read (buf);
if (ch <= 0) break;
fileOutputStream.write (buf, 0, ch);
} While (true);

is.close ();
fileOutputStream.close ();
haveDownLoad ();
} Catch (ClientProtocolException e) {
e.printStackTrace ();
} Catch (IOException e) {
e.printStackTrace ();
}
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Estimated download is wrong, print the contents of it under

No comments:

Post a Comment