Here you can find the source of removeSymlink(Path softLinkLocation)
public static void removeSymlink(Path softLinkLocation)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; public class Main { public static void removeSymlink(Path softLinkLocation) { try {/*from w w w . j a va2 s. c o m*/ BasicFileAttributes basicFileAttributes = getBasicFileAttributes(softLinkLocation); if (!basicFileAttributes.isSymbolicLink()) { throw new IOException("tried to delete a symlink which wasn't a symlink."); } Files.delete(softLinkLocation); } catch (IOException e) { System.err.println(e); } } static BasicFileAttributes getBasicFileAttributes(Path path) { return getBasicFileAttributes(path, new LinkOption[] { LinkOption.NOFOLLOW_LINKS }); } public static BasicFileAttributes getBasicFileAttributes(Path path, LinkOption[] options) { BasicFileAttributes basicFileAttributes; try { basicFileAttributes = Files.readAttributes(path, BasicFileAttributes.class, options); } catch (IOException e) { basicFileAttributes = null; // The file doesn't exist } return basicFileAttributes; } }