<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
Le 30/06/2010 18:00, John Hendrikx a écrit :
<blockquote cite="mid:4C2B6A37.10802@xs4all.nl" type="cite">Dear list,
<br>
<br>
I have a use case for NIO2, where I wish to present the user with a
list of FileStore's (or roots) from which to select one depending on
available space on the store. A loop as follows gives me the relevant
information in Java at the moment:
<br>
<br>
for(FileStore store : FileSystems.getDefault().getFileStores()) {
<br>
System.out.println(store);
<br>
}
<br>
<br>
This will print a list like this:
<br>
<br>
(C:)
<br>
data (D:)
<br>
New Volume (F:)
<br>
etc...
<br>
<br>
or on Linux:
<br>
<br>
/ (/dev/hda2)
<br>
/lib/init/rw (tmpfs)
<br>
/proc (proc)
<br>
/sys (sysfs)
<br>
/proc/bus/usb (procbususb)
<br>
/dev (udev)
<br>
/dev/shm (tmpfs)
<br>
/dev/pts (devpts)
<br>
/sys/fs/fuse/connections (fusectl)
<br>
/data (/dev/md0)
<br>
/temp (/dev/mapper/temp)
<br>
/raid1 (/dev/mapper/raid1)
<br>
/raid2 (/dev/mapper/raid2) <br>
<br>
It is fairly trivial to filter this list to only the stores useful to
the user (by discarding items with "non-sensical"
useableSpace()/totalSpace() values, ie. both being zero).
<br>
<br>
However, it turns out that after finding this treasure of information,
I cannot make use of it without parsing toString() of FileStore, as
there is no method to go from a FileStore to a (root) Path.
<br>
<br>
Is this an oversight or is there perhaps an even more elegant way to
find this information?
<br>
<br>
Note that even on Linux, with just "one" root (/), the added choice for
other volumes (which have different free space values) is invaluable
for the user. In other words, I'd like to present the user with the
choice of for example: /, /data, /temp, /raid1 and /raid2.
<br>
<br>
Thanks,
<br>
--John
<br>
<br>
</blockquote>
<br>
<br>
You can use fileSystem.getRootDirectories() and use getFileStore()<br>
on the resulting paths.<br>
<br>
<span class="Apple-style-span"
style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"></span>Rémi<br>
<br>
</body>
</html>