-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriterExample.java
More file actions
30 lines (23 loc) ยท 863 Bytes
/
WriterExample.java
File metadata and controls
30 lines (23 loc) ยท 863 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
package ch18.sec04.exam01;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
public class WriterExample {
public static void main(String[] args) {
try {
// ๋ฌธ์ ๊ธฐ๋ฐ ์ถ๋ ฅ ์คํธ๋ฆผ ์์ฑ
Writer writer = new FileWriter("temp/test.txt");
char a = 'A';
char b = 'B';
char[] arr = {'C', 'D', 'E'}; // ๋ฐฐ์ด ์ถ๋ ฅ
writer.write(a);
writer.write(b);
writer.write(arr);
writer.write("FGH"); // ๋ฌธ์์ด ์ถ๋ ฅ
writer.flush(); // ๋ฒํผ์ ์๋ฅํ๊ณ ์๋ ๋ฌธ์ ์ถ๋ ฅ ํ, ๋ฒํผ ๋น์ (stream : ๋ฌผ๊ฒฐ / flush : ํ๋ฌ ๋ณด๋)
writer.close(); // ์ถ๋ ฅ ์คํธ๋ฆผ์ ๋ซ๊ณ ๋ฉ๋ชจ๋ฆฌ ํด์
} catch (IOException e) {
e.printStackTrace();
}
}
}