-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReaderWriterMainV2.java
More file actions
34 lines (26 loc) · 972 Bytes
/
Copy pathReaderWriterMainV2.java
File metadata and controls
34 lines (26 loc) · 972 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
package io.text;
import java.io.*;
import java.nio.charset.StandardCharsets;
import static io.text.TextConst.FILE_NAME;
import static java.nio.charset.StandardCharsets.*;
public class ReaderWriterMainV2 {
public static void main(String[] args) throws IOException {
String writeString = "ABC";
System.out.println("write String = " + writeString);
// 파일에 쓰기
FileOutputStream fos = new FileOutputStream(FILE_NAME);
OutputStreamWriter osw = new OutputStreamWriter(fos, UTF_8);
osw.write(writeString);
osw.close();
// 파일을 읽기
FileInputStream fis = new FileInputStream(FILE_NAME);
InputStreamReader isr = new InputStreamReader(fis,UTF_8);
int ch;
StringBuilder sb = new StringBuilder();
while ((ch =isr.read()) != -1) {
sb.append((char)ch);
}
isr.close();
System.out.println("read String = " + sb);
}
}