-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
39 lines (32 loc) · 874 Bytes
/
Copy pathApp.java
File metadata and controls
39 lines (32 loc) · 874 Bytes
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
package tutorial29;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class App {
public static void main(String[] args) {
File file = new File("test.txt");
BufferedReader br = null;
try {
FileReader fr = new FileReader(file);
br = new BufferedReader(fr);
String line;
// readline only gets one line, so have to go till null
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (FileNotFoundException e) {
System.out.println("file not found: " + file);
} catch (IOException e) {
e.printStackTrace();
}
try {
br.close();
} catch (IOException e) {
System.out.println("File not closed, due to it not opening");
} catch (NullPointerException ex){
// no op
}
}
}