title: how to download a url as pdf in local file?
body: <p>I am trying to download the following url as pdf file in local folder.</p>
  
  <pre><code>http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&amp;arnumber=1498781&amp;tag=1
  </code></pre>
  
  <p>so far what i have tried is:</p>
  
  <pre><code>import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.URL;
  
  public class DownloadPDF {
  
      public DownloadPDF () {}
  
  
      public static String download (String link, String i) {
           String save = null;
  
           try{
               String file = link;
               URL url = new URL(file);
               InputStream in = url.openStream();
               save = "local_folder/name.pdf";    
               FileOutputStream fos = new FileOutputStream(new File(save));
  
               int length = -1;
               byte[] buffer = new byte[1024];
  
              while ((length = in.read(buffer)) &gt; -1) {
                   fos.write(buffer, 0, length);
              }
              fos.close();
              in.close();
              System.out.println("file is downloaded");
  
         } catch (IOException e) {
              e.printStackTrace();
         }
         return save;
      }  
  }
  </code></pre>
  
  <p>This works for:</p>
  
  <pre><code>http://ongambling.org/wp-content/uploads/2011/02/binde-2005-jgs-postprint.pdf
  </code></pre>
  
  <p>but does not work for the first url given above? is there any other suggestion?</p>