How to get the content of a directory?
In this example you'll see how to read the list of files inside a directory. To get this functionality we can use the
File.listFiles() method. This method return an array of
File object which can be either an instance of file or directory.
Here is the result of the program:
The File array returned:
D:GamesAOE is a directory
D:GamesChampionship Manager 2007 is a directory
D:GamesGameHouse is a directory
D:GamesSierra is a directory
D:Gamestesting.doc is a file
D:GamesTTD is a directory
The String array returned.
File = AOE
File = Championship Manager 2007
File = GameHouse
File = Sierra
File = testing.doc
File = TTD
The File array using FilenameFilter result.
Doc file = D:Gamestesting.doc