getting error as document is empty(size 0kb) when opening pdf file in micromax funbook
<p>Iam trying to Downloading pdf from server and displaying it as it is in android micromax funbook.</p>

<p>I am getting the error as document size is empty(0 KB).when open the pdf file...</p>

<p>I'm new to android suggest me the coding what i am using is correct or not for downloading</p>

<pre><code> public static void DownloadFile(String fileURL, File directory) {
    try {

                    FileOutputStream f = new FileOutputStream(directory);
                    URL u = new URL(fileURL);
                    HttpURLConnection c = (HttpURLConnection) u.openConnection();
                    c.setRequestMethod("GET");
                    c.setDoOutput(true);
                    c.connect();
                    InputStream in = c.getInputStream();
                    byte[] buffer = new byte[1024];
                    int len1 = 0;
                    while ((len1 = in.read(buffer)) &gt; 0) {
                            f.write(buffer, 0, len1);
                    }
                    f.close();
            } catch (Exception e) {
                    e.printStackTrace();
            }
    }
</code></pre>

<p>and the code for showing pdf.</p>

<pre><code>    public void showPdf() {
            File file = new File(Environment.getExternalStorageDirectory()
                    + "/pdf/Read.pdf");
            PackageManager packageManager = getPackageManager();
            Intent testIntent = new Intent(Intent.ACTION_VIEW);
            testIntent.setType("application/pdf");
            List list = packageManager.queryIntentActivities(testIntent,
                    PackageManager.MATCH_DEFAULT_ONLY);
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            Uri uri = Uri.fromFile(file);
            intent.setDataAndType(uri, "application/pdf");
            startActivity(intent);
        }
</code></pre>
