We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 90cd0d9 commit 0b7abf1Copy full SHA for 0b7abf1
src/com/howtodoinjava/io/IterateDirectoryExample.java
@@ -0,0 +1,27 @@
1
+package com.howtodoinjava.io;
2
+
3
+import java.io.File;
4
+import java.io.IOException;
5
+import java.nio.file.Files;
6
+import java.nio.file.Path;
7
+import java.nio.file.Paths;
8
+import java.util.List;
9
+import java.util.stream.Collectors;
10
11
+public class IterateDirectoryExample {
12
13
+ public static void main(String[] args) {
14
15
+ String dirLocation = "C:/temp";
16
17
+ try {
18
+ List<File> files = Files.list(Paths.get(dirLocation))
19
+ .map(Path::toFile)
20
+ .collect(Collectors.toList());
21
22
+ files.forEach(System.out::println);
23
+ } catch (IOException e) {
24
+ // Error while reading the directory
25
+ }
26
27
+}
0 commit comments