在 Linux 中运行时如何在 Java 中创建符号链接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4871748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make a symlink in Java when running in Linux?
提问by Juha Syrj?l?
How to make a symlink in Java/JVM when running in Linux? Are there any other ways to this than using Java Native Interface (JNI)or java.lang.Runtime.exec("/bin/ln -s /some/path symlink")
?
在 Linux 中运行时如何在 Java/JVM 中创建符号链接?除了使用Java Native Interface (JNI)或java.lang.Runtime.exec("/bin/ln -s /some/path symlink")
?
Creating a symlink is very platform dependant, but I mostly care about running on Linux, nice bonus would be if a shortcut would be created in Windows.
创建符号链接非常依赖于平台,但我最关心的是在 Linux 上运行,如果在 Windows 中创建快捷方式将是一个不错的奖励。
采纳答案by Joachim Sauer
The JDK 7includes (via NIO.2) a class called Files
that provides a createSymbolicLink()
method.
的JDK 7包括(通过NIO.2)一类叫做Files
,提供了一个createSymbolicLink()
方法。
Previous versions don't provide any built-in way to produce that, so JNI or Runtime.exec()
are your only real options.
以前的版本不提供任何内置方式来生成它,因此 JNI 或Runtime.exec()
是您唯一真正的选择。