Listing Files and Directories
We are going to examine how to list files and directories in different ways. These techniques can come in handy when checking whether a certain file exists, which will allow you to give more sensitive information to users when, for example, trying to find a properties file. If you detect that the file you're looking for doesn't exist and, at the same time, you notice that you are not in the right directory, you could make your program locate the actual folder in which the file resides, or you could simply inform the user about this situation.
Note
There are different techniques to list the files and directories at any location on your computer. You must choose wisely depending on the circumstances. While the latest API seems more complex at first sight, as you will see in the following examples, it is a lot more powerful than any of the previous versions.
Let's start with the old way of listing the contents of a directory. In the...