code: public static void replaceSymbolicLink(Path link, Path target) throws IOException {
          link = link.toAbsolutePath();
          if (Files.exists(link, NOFOLLOW_LINKS)) {
              if (!Files.isSymbolicLink(link)) {
                  throw new NotLinkException(String.format("%s is not a symbolic link", link));
              }
              // This operation will follow the link. And we want it to.
              Path parent = readCanonicalPath(link.getParent());
              Path temp   = parent.resolve(String.format("..tmp.%x", new Random().nextLong()));
              try {
                  Files.createSymbolicLink(temp, target);
                  Files.move(temp, link, ATOMIC_MOVE, REPLACE_EXISTING, NOFOLLOW_LINKS);
              } finally {
                  Files.deleteIfExists(temp);
              }
          } else {
              Files.createSymbolicLink(link, target);
          }
      }
docs: Similar to {@link Files#createSymbolicLink(Path, Path, FileAttribute[])}, but
  will replace the link if it already exists, and will try to write / replace
  it as an atomic operation.
  
  @param link The path of the symbolic link. The parent directory of the
  link file must already exist, and must be writable.
  See {@link Files#createDirectories(Path, FileAttribute[])}
  @param target The target path.
  @throws IOException If unable to create symbolic link.