简体   繁体   English

如何使用Java创建Windows符号链接(到UNC路径)

[英]How to create Windows Symbolic Link (to UNC path) with Java

I am trying to create symbolic link of folder on my machine to the shared drive of other m/c 我正在尝试在计算机上创建文件夹的符号链接到其他M / C的共享驱动器

ie If I have 'test' folder in D drive. 即如果我在D盘中有“测试”文件夹。 I want to create its Symbolic Link on shared folder say "\\\\hjds22\\Test". 我想在共享文件夹“ \\\\ hjds22 \\ Test”上创建其符号链接。 When I tried with below code it gives me java.nio.file.AccessDeniedException . 当我尝试以下代码时,它给了我java.nio.file.AccessDeniedException

Code is given below: 代码如下:

        Path newLink =Paths.get( "\\\\hjds22\\Test\\newLink");
        Path target = Paths.get("D:\\test");
        try {
            Files.createSymbolicLink(newLink, target);
        } catch (IOException x) {
            System.err.println(x);
        } catch (UnsupportedOperationException x) {
            // Some file systems do not support symbolic links.
            System.err.println(x);
        }

Note: I have full rights on shared folder. 注意:我对共享文件夹拥有full rights I have also executed fsutil behavior set SymlinkEvaluation L2L:1 R2R:1 L2R:1 R2L:1 on both m/c's. 我还在两个m / c上执行了fsutil behavior set SymlinkEvaluation L2L:1 R2R:1 L2R:1 R2L:1

Runtime.getRuntime().exec("mklink /j dir target")

Windows shortcuts are not supported by Java. Java不支持Windows快捷方式。

You have to use an external library. 您必须使用一个外部库。 Such as jShortcut , which comes with a jni dll. jShortcut ,它带有jni dll。

This works very fine, except that the dll is a 32bits dll. 除dll是32位dll以外,这工作得很好。 And I (personaly) failed to compile it to 64bits. 而且我(个人而言)未能将其编译为64位。 This will require to force your application to run with a 32bits jre. 这将要求您的应用程序以32位的jre运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM