2013-11-21 71 views
0

我想创建我的机器上的文件夹到其他m/c的共享驱动器的符号链接

即如果我有'测试'文件夹在D驱动器。我想在共享文件夹上创建符号链接,例如“\\ hjds22 \ Test”。当我尝试使用下面的代码时,它给了我java.nio.file.AccessDeniedException

守则如下:如何用Java创建Windows符号链接(到UNC路径)

 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); 
     } 

注:我对共享文件夹full rights。我还在两个m/c上执行了fsutil behavior set SymlinkEvaluation L2L:1 R2R:1 L2R:1 R2L:1

+0

什么是例外?驱动器是NTFS吗? – TJR

回答

0

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

0

的Windows快捷方式不支持Java。

您必须使用外部库。如jShortcut,它附带了一个jni dll。

这工作得很好,除了该DLL是一个32位的DLL。我(personaly)未能将其编译为64位。这将需要强制你的应用程序运行一个32位的jre。