在Java中获得硬链接计数 [英] get Hard Link Count in Java
问题描述
我需要一些东西来从java的solaris10操作系统中的文件中获取硬链接计数.
I need something to get the hard link count from a file in a solaris10 os in java.
无法解析ls -l.
我尝试将posix用于Java http://bmsi.com/java/posix/index.html 但无法使其正常工作.
I tried using posix for java http://bmsi.com/java/posix/index.html but couldn't manage to get it working.
是否还有其他轻量级API或代码来获取此信息?
Is there any other lightweight API or code to get this info?
推荐答案
在Java 7中,您可以使用新的.
In Java 7 you can use the new file attributes API to get it with
java.nio.file.Files.getAttribute(path, "unix:nlink")
.
"unix"属性视图实际上并未定义为标准API的一部分("posix"视图未提供nlink),但在标准Oracle/OpenJDK实现中可用.
另一方面,创建链接现在可以通过Files
上的标准createLink
方法使用.走吧.
The "unix" attribute view is not actually defined as part of the standard API (and the "posix" view does not give you nlink), but is available in the standard Oracle/OpenJDK implementation.
On the other hand creating a link is now available with the standard createLink
method on Files
. Go figure.
这篇关于在Java中获得硬链接计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!