How to get all files from a given directory?

To get all files from a given directory in java use following code.

public static File[] getFiles(String dirName)
        {
                File f = new File(dirName);
               
                return f.listFiles(new FilenameFilter() {
                        public boolean accept(File dir, String name)
                        {
                                return new File(dir + "" + System.getProperty("file.separator") + "" + name).isFile();
                        }
                });

               
        }

Search