在Java中获得硬链接计数 [英] get Hard Link Count in Java

查看:111
本文介绍了在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆