We can print volumes on which our drives are mounted and actual drives using below methods
Here getFileStores returns an iteratable of all volumes on our System.
Iterable<FileStore> stores = FileSystems.getDefault().getFileStores();
for(FileStore store :stores){
System.out.println("Voume name/drive letter "+store); //This will print name of volume name and driver letter.
System.out.println("File Store: "+store.name()); //This will print just the file store.
}
We can do things in another way as well. The way we will be doing it is not ideal though . but lets still try
It will print all drive letters like C:\ ,E:\ etc. It will print all available drive letters like it will also print E drive which is not always there on our System
but is only available when we connect a usb or phone to our pc
These methods to print drives are not very useful as there are are not many use cases as once an application is installed on a System ,it remembers
where it is installed . So we may never need to know root directories etc. but just in case we do the
method is below
Iterable<Path> rootPaths = FileSystems.getDefault().getRootDirectories();
for(Path path : rootPaths) {
System.out.println(path);
}