title: How to list directory items from a directory java
body: <p>I am building a program where the input is a directory path and the output should show all files in this path, <strong>including the files from a directory, which are in the given path.</strong> For example: <em>Input:</em> <strong>C:</strong> <em>Output:</em> <strong>C:/Directory1</strong> and <strong>C:/Directory1/file1.pdf.</strong></p>
  <pre><code>static string Directory = sc.next();
  static File folder = new File(Directory);
  static File[]listofFiles = folder.listFiles();
  
  public static void ListOfFilesInADirectory (final File folder) {
  for (int i = 0; i &lt; listofFiles.length; i++) { 
                if (listofFiles[i].isFile()) {           
                  System.out.println(&quot;File &quot; + listofFiles[i].getName());
                } else if (listofFiles[i].isDirectory()) { 
                  System.out.println(&quot;Directory &quot; + listofFiles[i].getName());
                }
              }
      }
  </code></pre>
  <p>The code above is the code for the input of the directory and the output of all the files in this directory, but not them in a folder, of this directory. How can I show the files in folders of the director too?</p>