1

I'm developing a Java software that reads lots of possibly big files.

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. 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. Is there a standardized way to do it?

Hikari
  • 3,797
  • 12
  • 47
  • 77
  • Does this answer your question? [Get the metadata of a file](https://stackoverflow.com/questions/10824027/get-the-metadata-of-a-file) – Progman Jun 13 '20 at 08:11
  • Tnx! These are nice info, but unfortunately none seems to inform precisely the device where the file is. – Hikari Jun 13 '20 at 13:45

1 Answers1

0

The sun.nio.fs.UnixFileAttributes class, which is used for PosixFileAttributes, contains a st_dev field. 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. Then you can use the device id to find out which device the file is on.

Also you might want to check the output of mount to check the paths you are using and where they are mounted on.

Progman
  • 16,827
  • 6
  • 33
  • 48