我怎样才能得到在Unix上的所有Java挂载的文件系统的列表? [英] How can I get a list of all mounted filesystems in Java on Unix?

查看:106
本文介绍了我怎样才能得到在Unix上的所有Java挂载的文件系统的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Unix平台上运行Java。我怎么能通过Java 1.6 API获得所有挂载文件系统的列表?



我试过 File.listRoots()但是会返回一个文件系统(也就是 / )。如果我使用 df -h 我可以看到更多:

 文件系统使用的大小可用容量iused ifree%iused安装在
/ dev / disk0s2上931Gi 843Gi 87Gi 91%221142498 22838244 91%/
devfs 187Ki 187Ki 0Bi 100%646 0 100%/ dev
map - 主机0Bi 0Bi 0Bi 100%0 0 100%/ net
map auto_home 0Bi 0Bi 0Bi 100%0 0 100%/ home
/ dev / disk1s2 1.8Ti 926Gi 937Gi 50%242689949 245596503 50%/ Volumes / MyBook
/ dev / disk2 1.0Gi 125Mi 875Mi 13%32014 223984 13%/ Volumes / Google Earth


解决方案 / div>

Java不提供对挂载点的访问。您必须通过 Runtime.exec()运行系统命令 mount 并解析其输出。或者解析 / etc / mtab 的内容。


I'm running Java on a Unix platform. How can I get a list of all mounted filesystems via the Java 1.6 API?

I've tried File.listRoots() but that returns a single filesystem (that is, /). If I use df -h I see more than that:

Filesystem      Size   Used  Avail Capacity   iused     ifree %iused  Mounted on
/dev/disk0s2   931Gi  843Gi   87Gi    91% 221142498  22838244   91%   /
devfs          187Ki  187Ki    0Bi   100%       646         0  100%   /dev
map -hosts       0Bi    0Bi    0Bi   100%         0         0  100%   /net
map auto_home    0Bi    0Bi    0Bi   100%         0         0  100%   /home
/dev/disk1s2   1.8Ti  926Gi  937Gi    50% 242689949 245596503   50%   /Volumes/MyBook
/dev/disk2     1.0Gi  125Mi  875Mi    13%     32014    223984   13%   /Volumes/Google Earth

I would expect to see /home as well (at a minimum).

解决方案

Java doesn't provide any access to mount points. You have to run system command mount via Runtime.exec() and parse its output. Either that, or parse the contents of /etc/mtab.

这篇关于我怎样才能得到在Unix上的所有Java挂载的文件系统的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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