Note that there are some explanatory texts on larger screens.

plurals
  1. POAPK file gets corrupted while writing to SD Card
    text
    copied!<p>I hit to a URL where my apk file is hosted and then write the bytes received to a file. </p> <pre><code>class DownloadAPKFile extends AsyncTask&lt;String, Void, Boolean&gt;{ private byte[] fileBytes; @Override protected Boolean doInBackground(String... params) { Log.d("begin", "begun"); HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet("http://www.website/Path/my.apk"); try { HttpResponse response = client.execute(get); Log.d("Login", "Response " + response.getEntity()); Log.d("Login", "contentLength " + response.getEntity().getContentLength()); String responseBody = EntityUtils.toString(response.getEntity()); fileBytes = responseBody.getBytes(); Log.d("fileBytes", "fileBytes"); String filePath = Environment.getExternalStorageDirectory() + "/myappdir/" + "my" + ".apk"; File file = new File(filePath); file.getParentFile().mkdirs(); file.createNewFile(); BufferedOutputStream objectOut = new BufferedOutputStream(new FileOutputStream(file)); Log.d("objectOut", "objectOut"); objectOut.write(fileBytes); Log.d("write", "write"); objectOut.close(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } } </code></pre> <p>This works like a charm, the problem i am having is that the content length from the entitiy is <code>582504</code> but when i look into the file manager the size goes upto <code>863145</code>. I think that some data is being added while writing file to SD Card. Is there any solution to this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload