title: Android - file download problem - incomplete file
body: <p>I have checked many code snippets, tried with and without buffer and I can't get to download whole file to SD card. The code I use currently is:</p>
  
  <pre><code>    try {
          url = new URL("http://mywebsite.com/directory/");
      } catch (MalformedURLException e1) { }
  
      String filename = "someKindOfFile.jpg"; // this won't be .jpg in future
  
      File folder = new File(PATH); // TODO: add checking if folder exist
      if (folder.mkdir()) Log.i("MKDIR", "Folder created");
      else Log.i("MKDIR", "Folder not created");
      File file = new File(folder, filename);
  
      try {
          conn = url.openConnection();
          is = conn.getInputStream();
  
          BufferedInputStream bis = new BufferedInputStream(is);
          ByteArrayBuffer baf = new ByteArrayBuffer(50);
          int current = 0;
          while ((current = bis.read()) != -1) {
                  baf.append((byte) current);
          }
          FileOutputStream fos = new FileOutputStream(file);
          fos.write(baf.toByteArray());
          fos.close();
          is.close();
      } catch (IOException e) { }
  </code></pre>
  
  <p>This code creates directory on SD card but downloads only 77 bytes of files. What might be the problem?</p>