-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileReaderTest.java
More file actions
46 lines (38 loc) · 980 Bytes
/
Copy pathFileReaderTest.java
File metadata and controls
46 lines (38 loc) · 980 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
40
41
42
43
44
45
46
package javaIO;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
public class FileReaderTest {
public static void main(String[] args) {
Reader is = null;
//InputStream is = null;
int count=0;
try {
is = new FileReader("/Users/choi/Desktop/cc.txt");
//is = new FileInputStream("/Users/choi/Desktop/cc.txt");
int data = -1;
while ((data = is.read()) != -1) {
//os.write(data);
System.out.print((char)data);
count++;
}
} catch (FileNotFoundException e) {
System.out.println("파일이 없습니다.");
}catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("입출력 오류." + e);
} finally {
System.out.println("\ncount is:"+count);
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}