List drives on a computer in Java

This piece of code might come in handy if you want to list the drives on a computer. Just call the static method listRoots() of the File class and it will return an array of File objects representing all the drives on your computer. In the example below we just loop through the array and print out each one. When we send in the whole object to the println() method of System.out the toString() method of the File class is called and the toString() method of the File class just calls its getPath() method.

And the same but doing it the lambda way:

Search for more Java info on this site here:
Custom Search

Please type any questions here.