Advertisement
Guest User

NIO directory listing

a guest
Dec 10th, 2012
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1.         Path dir = new File(pathname).toPath();
  2.         try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
  3.             for (Path file: stream) {
  4.                 System.out.println(file.getFileName());
  5.             }
  6.         } catch (IOException | DirectoryIteratorException x) {
  7.             // IOException can never be thrown by the iteration.
  8.             // In this snippet, it can only be thrown by newDirectoryStream.
  9.             System.err.println(x);
  10.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement