OSHI: Get HWDiskStore for a given path

喜欢而已 提交于 2020-07-30 08:13:32

问题


I am using OSHI https://github.com/oshi/oshi to monitor the hardware.

There is a method

HWDiskStore[] getDisks();

https://github.com/oshi/oshi/blob/master/oshi-core/src/main/java/oshi/hardware/Disks.java to get the list of all hard drives on the machine.

Is it possible to get HWDiskStore for a particular path like

FileStore getFileStore(Path path)

https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#getFileStore-java.nio.file.Path-

If no, what is a reliable way to match a HWDiskStore with a given path, e.g. use disk name or serial number, etc.?


回答1:


The DiskStore is a hardware object (e.g., hard drive, SSD, etc.) which is part of the machinery, while the FileStore is a software object associated with the Operating System / File System.

OSHI's HWDiskStore objects have a getPartitions() method, which returns an array of HWPartition objects. These objects have a getMountPoint() method which should be a String corresponding to the OSFileStore mount point.

OSHI's OSFileStore objects correspond to the Java FileStore objects and have a getMount() method which should directly match the HWPartition mount point.

This demo class gives an example of how this information can be correlated.



来源:https://stackoverflow.com/questions/53048059/oshi-get-hwdiskstore-for-a-given-path

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!