title: How to read the path that a broken symbolic link points to?
body: <p>If <code>symlink</code> is a File object that corresponds to a symbolic link, then:</p>
  
  <pre><code>File target = symlink.getCanonicalPath();
  </code></pre>
  
  <p>&hellip; succeeds in returning the target that it is pointing to. <code>Paths#toRealPath()</code> also works in the same situation.</p>
  
  <p>However, if the symbolic link is broken (dangling), both of the above APIs fail to return a <code>File</code> (or <code>Path</code>) representing the (non-existing) thing that it's pointing to.</p>
  
  <p>I am writing a tool that needs to be able to read those values, even for dangling symlinks. What API do I use to obtain the file or directory that a symlink points at (regardless of whether the symlink is correct or broken)?</p>
  
  <h1>update</h1>
  
  <p>Based on the accepted answer, one can obtain the target of the symlink (even a broken one) using:</p>
  
  <pre><code>Path target = Files.readSymbolicLink(Paths.get("/some/directory/symlink"));
  </code></pre>
  
  <p>&hellip; if <code>target</code> is then relative, you can de-reference it based on the location where the symlink itself is found by doing the following:</p>
  
  <pre><code>Paths.get("/some/directory/symlink").resolveSibling(".").resolve(target);
  </code></pre>