Getting the number of files in a folder in java [duplicate]
问题 This question already has answers here : Counting the number of files in a directory using Java (9 answers) Closed 4 years ago . I'm making a basic file browser and want to know how to get the number of files in any given directory (necessary for the for loops that add the files to the tree and table) 回答1: From javadocs: http://download.oracle.com/javase/6/docs/api/java/io/File.html You can use: new File("/path/to/folder").listFiles().length 回答2: new File(<directory path>).listFiles().length