title: Download all pdf files in website
body: <p>Trying to download all pdf files in the website and I have a bad code. I guess there is a better out there. Anyways here is it:</p>
  
  <pre><code>try {
          System.out.println("Download started");
          URL getURL = new URL("http://cs.lth.se/eda095/foerelaesningar/?no_cache=1");
          URL pdf;
          URLConnection urlC = getURL.openConnection();           
  
          InputStream is = urlC.getInputStream();
  
          BufferedReader buffRead = new BufferedReader(new InputStreamReader(is));
  
          FileOutputStream fos = null;
  
          byte[] b = new byte[1024];
  
          String line;
          double i = 1;
          int t = 1;
  
          int length;
          while((line = buffRead.readLine()) != null) {
  
              while((length = is.read(b)) &gt; -1) {
  
                  if(line.contains(".pdf")) {
  
                      pdf = new URL("http://fileadmin.cs.lth.se/cs/Education/EDA095/2015/lectures/" 
                      + "f" + i + "-" + t + "x" + t);
  
  
                      fos = new FileOutputStream(new File("fil" + i + "-" + t + "x" + t +  ".pdf"));
                      fos.write(b, 0, line.length());
                      i += 0.5;
                      t += 1;
  
                      if(t &gt; 2) {
                          t = 1;
                      }
                  }
              }
          }
          is.close();
          System.out.println("Download finished");
      } catch (MalformedURLException e) {
  
          e.printStackTrace();
      } catch (IOException e) {
  
          e.printStackTrace();
      }
  </code></pre>
  
  <p>The files I get is damage, BUT is there a better way to download the PDF files? Because on the site some of the files are f1-1x1, f1-2x2, f2-1x1.. But what IF the files were donalds.pdf stack.pdf etc.. </p>
  
  <p>So the question would be, How do I make my code better to download all the pdf files? </p>