- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtutorial_47.java
More file actions
Latest commit
27 lines (22 loc) · 1.08 KB
/
Copy pathtutorial_47.java
File metadata and controls
27 lines (22 loc) · 1.08 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
importjava.io.FileReader;
importjava.io.BufferedReader;
importjava.io.FileNotFoundException;
classFiles {
publicstaticvoidmain(String[] args) throwsjava.io.IOException {
StringfilePath = "file.txt"; // or a full path - "c:/users/jeremy/desktop/java/file.txt"
StringnextLine = null;
try (BufferedReaderbr = newBufferedReader(newFileReader(filePath))) {
while ((nextLine = br.readLine()) != null) {
System.out.println( nextLine );
}
}
catch (FileNotFoundExceptione) {
System.out.println(e.getLocalizedMessage()); // display the error, but continue on with our code.
}
catch (java.io.IOExceptione) {
System.out.println("Shutting down the program because there was an error reading or closing the file.");
throwe; // 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...");
}
}