title: Joining paths in Java
body: <p>In <code>Python</code> I can join two paths with <code>os.path.join</code>:</p>
  
  <pre><code>os.path.join("foo", "bar") # =&gt; "foo/bar"
  </code></pre>
  
  <p>I'm trying to  achive the same in Java, without worrying if the <code>OS</code> is <code>Unix</code>, <code>Solaris</code> or <code>Windows</code>:</p>
  
  <pre><code>public static void main(String[] args) {
      Path currentRelativePath = Paths.get("");
      String current_dir = currentRelativePath.toAbsolutePath().toString();
      String filename = "data/foo.txt";
      Path filepath = currentRelativePath.resolve(filename);
  
      // "data/foo.txt"
      System.out.println(filepath);
  
  }
  </code></pre>
  
  <p>I was expecting that <code>Path.resolve( )</code> would join my current directory <code>/home/user/test</code> with <code>data/foo.txt</code> making <code>/home/user/test/data/foo.txt</code>.
  What am I getting wrong?</p>