title: openning pdf file in android from server gives me this error document is empty
body: <p>when I click button download, pdf opens but gives me this message document is empty 0ko plz if you any suggessions,I use my phone, and I send the  acrobat reader adobe file in my phone and i have adobe acrobat in my phone..</p>
  
  <p>this Mainactivity.java</p>
  
  <pre><code>    package com.example.down1;
  
  import java.io.File;
  import java.io.IOException;
  
  import android.app.Activity;
  import android.content.ActivityNotFoundException;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.os.Environment;
  import android.view.Menu;
  import android.view.View;
  import android.widget.Toast;
  
  public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      public void download(View v)
      {
          new DownloadFile().execute("http://172.16.2.138/upload/guide.pdf", "guide.pdf"); 
      }
  
      public void view(View v)
      {
          File pdfFile = new File(Environment.getExternalStorageDirectory() + "/uploade/" + "guide.pdf");  // -&gt; filename = maven.pdf
          Uri path = Uri.fromFile(pdfFile);
          Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
  
          pdfIntent.setDataAndType(path, "application/pdf");
          pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            //Intent intent = Intent.createChooser(pdfIntent, "Open File");
  
  
              startActivity(pdfIntent);
  
      }
  
      private class DownloadFile extends AsyncTask&lt;String, Void, Void&gt;{
  
          @Override
          protected Void doInBackground(String... strings) {
              String fileUrl = strings[0];   // -&gt; http://maven.apache.org/maven-1.x/maven.pdf
              String fileName = strings[1];  // -&gt; maven.pdf
              String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
              File folder = new File(extStorageDirectory, "uploade");
              folder.mkdir();
  
              File pdfFile = new File(folder, fileName);
  
              try{
                  pdfFile.createNewFile();
              }catch (IOException e){
                  e.printStackTrace();
              }
              FileDownloader.downloadFile(fileUrl, pdfFile);
              return null;
          }
      }
  
  
  }
  this is my class filedownloader
  
      package com.example.down1;
  
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.HttpURLConnection;
  import java.net.MalformedURLException;
  import java.net.URL;
  
  public class FileDownloader {
      private static final int  MEGABYTE = 1024 * 1024;
  
      public static void downloadFile(String fileUrl, File directory){
          try {
  
              URL url = new URL(fileUrl);
              HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
              //urlConnection.setRequestMethod("GET");
              //urlConnection.setDoOutput(true);
              urlConnection.connect();
  
              InputStream inputStream = urlConnection.getInputStream();
              FileOutputStream fileOutputStream = new FileOutputStream(directory);
              int totalSize = urlConnection.getContentLength();
  
              byte[] buffer = new byte[MEGABYTE];
              int bufferLength = 0;
              while((bufferLength = inputStream.read(buffer))&gt;0 ){
                  fileOutputStream.write(buffer, 0, bufferLength);
              }
              fileOutputStream.close();
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>