title: Download pdf files from local systems tomcat directory
body: <p>I want to download a pdf file when user clicks on button.For front end I am using JSF 2.
  Actually I want to download pdf files <a href="http://www.primefaces.org/showcase/ui/fileDownload.jsf" rel="nofollow">download image</a>as shown in primefaces demo </p>
  
  <p>pdf files are stored on my local tomcat's inside Root folder.
  I am following in this way but it's giving me exception as </p>
  
  <blockquote>
    <p>java.io.IOException: Server returned HTTP response code: 505 for
    URL:</p>
  </blockquote>
  
  <pre><code>URL url;
          URLConnection con;
          DataInputStream dis; 
          FileOutputStream fos; 
          byte[] fileData;  
          try {
              url = new URL("http://localhost:8080/html/pdf/sample.pdf"); //File download Location goes here
  
              System.out.println("URL "+url.toString());
              con = url.openConnection(); // open the url connection.
              dis = new DataInputStream(con.getInputStream());
              fileData = new byte[con.getContentLength()]; 
              for (int q = 0; q &lt; fileData.length; q++) { 
                  fileData[q] = dis.readByte();
              }
              dis.close(); // close the data input stream
              fos = new FileOutputStream(new File("/Users/sample.pdf")); //FILE Save Location goes here
              fos.write(fileData);  // write out the file we want to save.
              fos.close(); // close the output stream writer
          }
          catch(Exception m) {
              System.out.println(m);
          }
  </code></pre>
  
  <blockquote>
    <p>Is I am providing wrong path? If yes what is the correct path to
    download file from local systems tomcat folder as shown ?</p>
  </blockquote>