问题
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