FileStore... getRootPath() ?

Rémi Forax forax at univ-mlv.fr
Wed Jun 30 09:49:40 PDT 2010


Le 30/06/2010 18:00, John Hendrikx a écrit :
> Dear list,
>
> 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:
>
> for(FileStore store : FileSystems.getDefault().getFileStores()) {
>  System.out.println(store);
> }
>
> This will print a list like this:
>
> (C:)
> data (D:)
> New Volume (F:)
> etc...
>
> or on Linux:
>
> / (/dev/hda2)
> /lib/init/rw (tmpfs)
> /proc (proc)
> /sys (sysfs)
> /proc/bus/usb (procbususb)
> /dev (udev)
> /dev/shm (tmpfs)
> /dev/pts (devpts)
> /sys/fs/fuse/connections (fusectl)
> /data (/dev/md0)
> /temp (/dev/mapper/temp)
> /raid1 (/dev/mapper/raid1)
> /raid2 (/dev/mapper/raid2)
>
> 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).
>
> 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.
>
> Is this an oversight or is there perhaps an even more elegant way to 
> find this information?
>
> 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.
>
> Thanks,
> --John
>


You can use fileSystem.getRootDirectories() and use getFileStore()
on the resulting paths.

Rémi

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20100630/1b320039/attachment.html 


More information about the nio-dev mailing list