title: Java get parent of parent
body: <p>This is a very similar question to this one: <a href="https://stackoverflow.com/questions/8197049/how-to-get-just-the-parent-directory-name-of-a-specific-file">How to get just the parent directory name of a specific file</a></p>
  
  <p>But there he wanted to get just the closest Parent directory, what I want is to be able to select other "Parents" such as:</p>
  
  <p><strong>bbb</strong> or <strong>ccc</strong> (considering the same example on the mentioned question)</p>
  
  <p>File file = new File("C:/aaa/bbb/ccc/ddd/test.java");</p>
  
  <p>I tried <code>file.getParent().getParent();</code> which didn't work.</p>
  
  <p>Note: if possible I don't want to use regex on the path. </p>