IOUtils { public static List<String> listDirectory(File dir, FilenameFilter filter) throws IOException { ArrayList<String> list = new ArrayList<String> (); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir.toPath())) { for (Path entry: stream) { Path fileName = entry.getFileName(); if (fileName != null) { String fileNameStr = fileName.toString(); if ((filter == null) || filter.accept(dir, fileNameStr)) { list.add(fileNameStr); } } } } catch (DirectoryIteratorException e) { throw e.getCause(); } return list; }  static void copyBytes(InputStream in, OutputStream out,
                               int buffSize, boolean close); static void copyBytes(InputStream in, OutputStream out, int buffSize); static void copyBytes(InputStream in, OutputStream out, Configuration conf); static void copyBytes(InputStream in, OutputStream out, Configuration conf, boolean close); static void copyBytes(InputStream in, OutputStream out, long count,
      boolean close); static int wrappedReadForCompressedData(InputStream is, byte[] buf,
      int off, int len); static void readFully(InputStream in, byte[] buf,
      int off, int len); static void skipFully(InputStream in, long len); @Deprecated static void cleanup(Log log, java.io.Closeable... closeables); static void cleanupWithLogger(Logger logger,
      java.io.Closeable... closeables); static void closeStream(java.io.Closeable stream); static void closeStreams(java.io.Closeable... streams); static void closeSocket(Socket sock); static void writeFully(WritableByteChannel bc, ByteBuffer buf); static void writeFully(FileChannel fc, ByteBuffer buf,
      long offset); static List<String> listDirectory(File dir, FilenameFilter filter); static void fsync(File fileToSync); static void fsync(FileChannel channel, boolean isDir); static IOException wrapException(final String path,
      final String methodName, final IOException exception); static byte[] readFullyToByteArray(DataInput in); static final Logger LOG; }
@Test public void testListDirectory() throws IOException { File dir = new File("testListDirectory"); Files.createDirectory(dir.toPath()); try { Set<String> entries = new HashSet<String>(); entries.add("entry1"); entries.add("entry2"); entries.add("entry3"); for (String entry : entries) { Files.createDirectory(new File(dir, entry).toPath()); } List<String> list = IOUtils.listDirectory(dir, NoEntry3Filter.INSTANCE); for (String entry : list) { Assert.assertTrue(entries.remove(entry)); } Assert.assertTrue(entries.contains("entry3")); list = IOUtils.listDirectory(dir, null); for (String entry : list) { entries.remove(entry); } Assert.assertTrue(entries.isEmpty()); } finally { FileUtils.deleteDirectory(dir); } }