downloading file in sdcard showing size 0
<p>I have following code for downloading file from url to sdcard . This code is working fine for small file , but when the file size is large i am getting the downloaded file size 0.
Any help would be appreciated.</p>

<p><strong>Java Code</strong></p>

<pre><code>setContentView(R.layout.activity_download_file);
        String exStorageDirectory = Environment.getExternalStorageDirectory()
                .toString();
        File folder = new File(exStorageDirectory, "Folder");
        folder.mkdir();
        File file = new File(folder, "scjp.pdf");
        try {
            if (!file.exists()) {
                file.createNewFile();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        downloadFile(
                "http://java.net/downloads/jfjug/SCJP%20Sun%20Certified%20Programmer%20for%20Java%206-0071591060.pdf",
                file);

    }

    private void downloadFile(String fileUrl, File directory) {
        try {
            FileOutputStream fileOutput = new FileOutputStream(directory);
            URL url = new URL(fileUrl);
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setRequestMethod("GET");
            connection.setDoOutput(true);
            connection.connect();
            InputStream inputStream = connection.getInputStream();
            byte buffer[] = new byte[1024];
            int len = 0;
            while ((len = inputStream.read(buffer)) &gt; 0) {

                fileOutput.write(buffer, 0, len);

            }

            fileOutput.close();
            Thread.sleep(10000);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
</code></pre>
