-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIO.java
More file actions
27 lines (26 loc) · 727 Bytes
/
IO.java
File metadata and controls
27 lines (26 loc) · 727 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
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class IO{
public static void main(String[] args){
String file = "/Users/dengwei/hosts";
String line = null;
try {
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
bufferedReader.close();
}
catch(FileNotFoundException fe){
System.out.println("Not found " + file);
}
catch(IOException ioe){
System.out.println("Err while reading file " + file);
ioe.printStackTrace();
}
}
}