file.listRoots()
works fine for internal file drive information, but is not getting USB and portable file info. Here is my code:
File[] paths;
try {
// returns pathnames for files and directory
paths = File.listRoots();
for (File path : paths) // for each pathname in pathname array
System.out.println(path); // prints file and directory paths
} catch(Exception e) { // if any error occurs
e.printStackTrace();
}
I don't understand why does my portable USB info not fetch?
If your USB drive is connected and is accessible, you could check whether NIO code shows the volumes as follows:
Inside above loop you can also check other filesystem attributes such as removable storage flag: