Skip to content

Commit 0a855fb

Browse files
committed
files.walk
1 parent a98c3ac commit 0a855fb

3 files changed

Lines changed: 8 additions & 14 deletions

File tree

java-basic/src/test/resources/database.properties

Lines changed: 0 additions & 4 deletions
This file was deleted.

java-basic/src/test/resources/json/file1.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

java-io/src/main/java/com/mkyong/io/api/FilesWalkExample.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.nio.file.attribute.FileTime;
88
import java.time.Instant;
99
import java.time.temporal.ChronoUnit;
10+
import java.util.List;
11+
import java.util.stream.Collectors;
1012
import java.util.stream.Stream;
1113

1214
// Files.walk example
@@ -30,7 +32,7 @@ public static void main(String[] args) throws IOException {
3032
}
3133

3234
// list all files from this path
33-
/*public static List<Path> listFiles(Path path) throws IOException {
35+
public static List<Path> listFiles(Path path) throws IOException {
3436

3537
List<Path> result;
3638
//try (Stream<Path> walk = Files.walk(path, 1)) {
@@ -40,10 +42,10 @@ public static void main(String[] args) throws IOException {
4042
}
4143
return result;
4244

43-
}*/
45+
}
4446

4547
// list all directories from this path
46-
/*public static List<Path> listDirectories(Path path) throws IOException {
48+
public static List<Path> listDirectories(Path path) throws IOException {
4749

4850
List<Path> result;
4951
try (Stream<Path> walk = Files.walk(path)) {
@@ -89,10 +91,10 @@ public static List<Path> findByFileName(Path path, String fileName) throws IOExc
8991
}
9092
return result;
9193

92-
}*/
94+
}
9395

9496
// fileSize in bytes
95-
/*public static List<Path> findByFileSize(Path path, long fileSize) throws IOException {
97+
public static List<Path> findByFileSize(Path path, long fileSize) throws IOException {
9698

9799
if (!Files.isDirectory(path)) {
98100
throw new IllegalArgumentException("Path must be a directory!");
@@ -121,7 +123,7 @@ private static boolean checkFileSize(Path path, long fileSize) {
121123
System.err.println("Unable to get the file size of this file: " + path);
122124
}
123125
return result;
124-
}*/
126+
}
125127

126128
// set all files' last modified time to this instant
127129
public static void setAllFilesModifiedDate(Path path, Instant instant) throws IOException {

0 commit comments

Comments
 (0)