简体   繁体   English

如何识别文件在哪个存储设备中

[英]How to identify in which storage device a file is

I'm developing a Java software that reads lots of possibly big files.我正在开发一个 Java 软件,它可以读取很多可能的大文件。

I'll try to parallelize it, so it reads in parallel files from different devices (HDD, SSD, flash drive, SMB, etc) and only 1 file at a time from each device.我将尝试并行化它,因此它从不同的设备(HDD、SSD、flash 驱动器、SMB 等)读取并行文件,并且每次只能从每个设备读取 1 个文件。 But for that I'd need to know in which device a given file is.但为此,我需要知道给定文件在哪个设备中。

On Windows I guess I could just use substring its path for the drive letter, but for Linux I have no idea how that could be done.在 Windows 我想我可以只使用 substring 它的驱动器号路径,但对于 Linux 我不知道怎么做。 Is there a standardized way to do it?有没有标准化的方法来做到这一点?

The sun.nio.fs.UnixFileAttributes class, which is used for PosixFileAttributes , contains a st_dev field.用于PosixFileAttributessun.nio.fs.UnixFileAttributes class 包含一个st_dev字段。 Unfortunately, it is not public accessible, you might have to use reflection to get the value.不幸的是,它不是公共可访问的,您可能必须使用反射来获取值。

A different approach would be to call stat on the file and read the device id that way.另一种方法是在文件上调用stat并以这种方式读取设备 ID。 Then you can use the device id to find out which device the file is on.然后您可以使用设备 id 找出文件在哪个设备上。

Also you might want to check the output of mount to check the paths you are using and where they are mounted on.此外,您可能需要检查mount的 output 以检查您正在使用的路径以及它们的安装位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM