title: How to read all files and folders "recursively" through a url link
body: <p>I'm trying to download all files from a URL. But, analyzing the code through the chrome developer tools, I can see that the files I need are in a path as example: <strong><code>/var/www/html/folders_and_files_that_i_need</code></strong>. </p>
  
  <p>Someone have any idea to help me? Thanks in advance.</p>
  
  <p>My code actually can only download the file setting absolute path.</p>
  
  <pre><code>public static void downloadFile(String fileURL, String saveDir) throws IOException {
      URL url = new URL(fileURL);
      HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
      int responseCode = httpConn.getResponseCode();
  
      // always check HTTP response code first
      if (responseCode == HttpURLConnection.HTTP_OK) {
          String fileName = "";
          String disposition = httpConn.getHeaderField("Content-Disposition");
          String contentType = httpConn.getContentType();
          int contentLength = httpConn.getContentLength();
  
          if (disposition != null) {
              // extracts file name from header field
              int index = disposition.indexOf("filename=");
              if (index &gt; 0) {
                  fileName = disposition.substring(index + 10, disposition.length() - 1);
              }
          } else {
              // extracts file name from URL
              fileName = fileURL.substring(fileURL.lastIndexOf("/") + 1, fileURL.length());
          }
  
          System.out.println("Content-Type = " + contentType);
          System.out.println("Content-Disposition = " + disposition);
          System.out.println("Content-Length = " + contentLength);
          System.out.println("fileName = " + fileName);
  
          // opens input stream from the HTTP connection
          InputStream inputStream = httpConn.getInputStream();
          String saveFilePath = saveDir + File.separator + fileName;
  
          // opens an output stream to save into file
          FileOutputStream outputStream = new FileOutputStream(saveFilePath);
  
          int bytesRead = -1;
          byte[] buffer = new byte[BUFFER_SIZE];
          while ((bytesRead = inputStream.read(buffer)) != -1) {
              outputStream.write(buffer, 0, bytesRead);
              System.out.println("buffering");
          }
  
          outputStream.close();
          inputStream.close();
  
          System.out.println("Arquivo " + fileName + " baixado");
      } else {
          System.out.println("No file to download. Server replied HTTP code: " + responseCode);
      }
      httpConn.disconnect();
  }
  </code></pre>