title: Creating a symbolic link with Java
body: <p>I'm having trouble creating a symbolic link to a directory in Java. I'm using the createSymbolicLink() method from the Files class: <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html" rel="noreferrer">http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html</a></p>
  
  <p>Absolute paths:</p>
  
  <ul>
  <li>Target: <code>/some/path/target</code> </li>
  <li>Link: <code>/some/path/xxx/linkname</code></li>
  </ul>
  
  <p>I would expect that a link in the directory <code>/some/path/xxx/</code> is created to the folder <code>/some/path/target</code>, but instead a link from <code>/some/path/xxx/linkname</code> to <code>/some/path/xxx/target</code> is created. I just can't figure out what I'm doing wrong.</p>
  
  <p>When I create a link from <code>/some/path/linkname</code> to <code>/some/path/target</code>, everything works as expected.</p>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>EDIT: 
  Here's my code:</p>
  
  <pre><code>Path records = Paths.get(Properties.getProperty("records.path"));
  Path recordsLink = Paths.get(Properties.getProperty("webserver.root") + System.getProperty("file.separator") + records.getFileName());
  try {
      Files.createSymbolicLink(recordsLink, records);
  } catch (IOException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>The "records.path" and "webserver.root" are both relative paths.</p>
  
  <p><strong>Actually I just found a solution to the problem</strong>: It works if I do this:</p>
  
  <pre><code>records = records.toAbsolutePath();
  </code></pre>
  
  <p>I assumed the <code>createSymbolicLink()</code> will use absolute paths to create the links, which was wrong.</p>