-
Notifications
You must be signed in to change notification settings - Fork 0
/
calcMax.java
54 lines (48 loc) · 1.54 KB
/
calcMax.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.io.PrintWriter;
import java.util.stream.Stream;
import java.util.ArrayList;
public class calcMax {
public static void main(String args[]) {
File folder = new File("exemplaires");
try {
PrintWriter writer = new PrintWriter("maxValues.txt", "UTF-8");
listAllFiles(folder, writer);
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void listAllFiles(File folder, PrintWriter writer) {
File[] fileNames = folder.listFiles();
for (File file : fileNames) {
try {
readContent(file, writer);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void readContent(File file, PrintWriter writer) throws IOException {
long max = 0;
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String strLine;
// Read lines from the file, returns null when end of stream
// is reached
while ((strLine = br.readLine()) != null) {
if (Long.parseLong(strLine) > max) {
max = Long.parseLong(strLine);
}
}
writer.print(file + ", ");
writer.println(max);
}
}
}