title: Java - Display relative path to a root directory
body: <p>I am writing a small <code>Java</code> program to list files in a root directory recursively. This is the code I used.</p>
  
  <pre><code>public static void displayDirectoryContents(File dir) {
      File[] files = dir.listFiles();
      for (File file : files) {
          if (file.isDirectory()) {
              displayDirectoryContents(file);
          } else {
              System.out.println(file.getPath());
          }
      }
  }
  
  public static void main(String[] args) throws IOException {
      File currentDir = new File("root-direcotry");
      displayDirectoryContents(currentDir);
  }
  </code></pre>
  
  <p>The result I got is something like:</p>
  
  <pre><code>root-direcotry/1.txt
  root-direcotry/2.txt
  root-direcotry/t1/a.txt
  root-direcotry/t2/b.txt
  root-direcotry/t4/c.txt
  </code></pre>
  
  <p>My question is can I just display the relative path without the "<em>root-direcotry</em>"? </p>
  
  <p>i.e. What I want to achieve is displaying:</p>
  
  <pre><code>/1.txt
  /2.txt
  /t1/a.txt
  /t2/b.txt
  /t4/c.txt
  </code></pre>
  
  <p>I prefer not using any <code>String</code> method to just not display that part.
  Thank you!</p>