title: How to get the absolute path of a file when given a relative or absolute path and the absolute path it is relative to
body: <p>Let's say I have an absolute 'base' path:</p>
  
  <pre><code>/home/someone/dir1/dir2/
  </code></pre>
  
  <p>The user can pass me a new path, that can either be absolute or relative to base path, so the following would both be valid:</p>
  
  <pre><code>..
  /home/someone/dir1/
  </code></pre>
  
  <p>How do I get java to give me the correct absolute path ie for both these cases:</p>
  
  <pre><code>/home/someone/dir1/
  </code></pre>
  
  <p>and do this in a platform-independent way?</p>
  
  <p>I tried the following:</p>
  
  <pre><code>File resolvedFile = new File((new File(basePath).toURI().resolve(new File(newPath).toURI())));
  </code></pre>
  
  <p>However, where newPath was relative, newFile(newPath) resolves it automatically against the current working directory, rather than the basePath I want to supply.</p>
  
  <p>Any thoughts?
  Many thanks!</p>