删除java中的符号链接

问题描述:

是否有任何 api 可用于使用 java.ini 删除符号链接?Files.delete(Path) 无效.请发表您的建议.

Is there any api available to delete a symbolic link using java. Files.delete(Path) didn't work out.Please post your suggestions.

Files.delete(Path) 在符号链接上工作得很好.您的代码中应该还有其他问题.

Files.delete(Path) is working perfectly on symbolic links. You should have a other issue in your code.

此代码示例有效(JAVA 8):

This code sample works (JAVA 8):

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
...
String symLinkName = "/some/path/to/symlink";
try {               
    if(Files.exists(Paths.get(symLinkName))) {              
        Files.delete(Paths.get(symLinkName));
    }
} catch (IOException e) {
    log.info("Cannot delete symbolic link " + symLinkName);
    e.printStackTrace();
}

记住符号链接是一个 UNIX 概念,在 Windows 上不存在

Remember that symbolic links are a UNIX concept and does not exist on Windows