-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadFile.java
29 lines (26 loc) · 939 Bytes
/
ReadFile.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;
public class ReadFile {
public static void main(String[] args) {
try (Stream<Path> files = Files.list(Paths.get("/home/gaian/IdeaProjects/quiz/src"))) {
long count = files.count();
System.out.println("There are "+count +".java files ");
} catch (IOException e) {
throw new RuntimeException(e);
}
File dir = new File("/home/gaian/IdeaProjects/quiz/src");
if (dir.isDirectory()) {
File[] files = dir.listFiles();
for (File file : files) {
if (file.getName().contains(".java")) {
System.out.println(file.getName()+" "+file.getAbsolutePath());
}
}
}
}
}