forked from pratyushmp/code_opensource_2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadFile.java
More file actions
26 lines (23 loc) · 693 Bytes
/
ReadFile.java
File metadata and controls
26 lines (23 loc) · 693 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
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
/**
* This program will read a file and print each line
*
*/
public class ReadFile {
public static void main(String[] args) throws IOException {
File file = new File("C:/Users/x88195/Documents/Other/Files/file.txt");
// Opening resource in a try block to handle File IO exceptions and close stream
// after operation is complete
try (BufferedReader in = new BufferedReader(new FileReader(file))) {
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
System.err.println("Exception:" + e);
}
}
}