-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtutorial_47.java
27 lines (22 loc) · 1.08 KB
/
tutorial_47.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
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
class Files {
public static void main(String[] args) throws java.io.IOException {
String filePath = "file.txt"; // or a full path - "c:/users/jeremy/desktop/java/file.txt"
String nextLine = null;
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
while ((nextLine = br.readLine()) != null) {
System.out.println( nextLine );
}
}
catch (FileNotFoundException e) {
System.out.println(e.getLocalizedMessage()); // display the error, but continue on with our code.
}
catch (java.io.IOException e) {
System.out.println("Shutting down the program because there was an error reading or closing the file.");
throw e; // means I have to add ( throws java.io.IOException ) to the end of my method header because I am throwing a Checked Exception.
}
System.out.println("stuff here blah blah...");
}
}