-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineCounter.java
More file actions
62 lines (51 loc) · 1.63 KB
/
LineCounter.java
File metadata and controls
62 lines (51 loc) · 1.63 KB
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
55
56
57
58
59
60
61
62
package Fach_6_FileIO;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
/**
* Created by RETO KAUFMANN
*/
public class LineCounter {
public static void main(String[] args) {
int counter = 0;
BufferedReader bufferedReader = null;
try {
File inputFile = new File("src/pruefungsresultat/songs.txt");
bufferedReader = new BufferedReader(new FileReader(inputFile));
String line;
while ((line = bufferedReader.readLine()) != null) {
counter++;
System.out.println("Zeile: " + line);
}
System.out.println("Zeilen:" + counter);
} catch (IOException e) {
e.printStackTrace();
} finally {
// Ob OK oder Fehler, auf jeden Fall schliessen
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// WRITE STATS FILE
FileWriter out = null;
File staticFile = new File("src/pruefungsresultat/statistic.txt");
try {
out = new FileWriter(staticFile);
out.write(String.valueOf(counter));
System.out.println("file geschrieben, stats: " +counter );
} catch (IOException e) {
e.printStackTrace();
} finally {
// Ob OK oder Fehler, auf jeden Fall schliessen
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}