title: Check if file is in (sub)directory
body: <p>I would like to check whether an existing file is in a specific directory or a subdirectory  of that.</p>
  
  <p>I have two File objects.</p>
  
  <pre><code>File dir;
  File file;
  </code></pre>
  
  <p>Both are guaranteed to exist. Let's assume </p>
  
  <pre><code>dir  = /tmp/dir 
  file = /tmp/dir/subdir1/subdir2/file.txt
  </code></pre>
  
  <p>I want this check to return true</p>
  
  <p>For now i am doing the check this way:</p>
  
  <pre><code>String canonicalDir = dir.getCanonicalPath() + File.separator;
  boolean subdir = file.getCanonicalPath().startsWith(canonicalDir);
  </code></pre>
  
  <p>This seems to work with my limited tests, but i am unsure whether this might make problems on some operating systems. I also do not like that getCanonicalPath() can throw an IOException which i have to handle.</p>
  
  <p>Is there a better way? Possibly in some library?</p>
  
  <p>Thanks</p>