Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • You should actually call listFiles() ;) Commented Apr 17, 2011 at 15:48
  • @Progman Could be helpful. :) Commented Apr 17, 2011 at 15:50
  • 19
    You can put a filter on listFiles so as to only return files with a certain extension File[] files = new File("/path/to/the/directory").listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".xml"); } }); Commented Feb 18, 2016 at 18:27
  • 4
    File[] files = new File(fullPath).listFiles(); List<String> names = Arrays.asList(files).parallelStream().map(file -> file.getName()).collect(Collectors.toList()); Commented Jun 14, 2017 at 14:04
  • 4
    You can filter files using lambda expression (Java 8+): File[] files = new File("path/to/dir").listFiles((dir, name) -> name.endsWith(".xml")); Commented Jun 25, 2018 at 8:32