-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoneList01.java
More file actions
74 lines (61 loc) · 1.67 KB
/
Copy pathPhoneList01.java
File metadata and controls
74 lines (61 loc) · 1.67 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package javaIO;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class PhoneList01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
BufferedReader br = null;
try {
File file = new File("src/javaIO/phone.txt");
if (file.exists() == false) {
System.out.println("file not found");
return;
}
System.out.println("====파일정보====");
System.out.println(file.getAbsolutePath());
System.out.println(file.length() + "byte");
System.out.println(file.lastModified());
System.out.println("=====전화번호=====");
// 기반스트림(byte)
FileInputStream fis = new FileInputStream(file);
// 보조스트림1(bytes->char)
InputStreamReader isr = new InputStreamReader(fis);
// 보조스트림 (라인입력)
br = new BufferedReader(isr);
// 처리
String line = null;
while ((line = br.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line, "\t ");
int idx = 0;
while (st.hasMoreElements() == true) {
String token = st.nextToken();
System.out.print(token);
if (idx == 0) {
System.out.print(": ");
} else if (idx == 1) {
System.out.print("-");
} else if (idx == 2) {
System.out.print("-");
}
idx++;
}
System.out.println();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (br != null)
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}