-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTextFileTest.java
More file actions
30 lines (26 loc) · 893 Bytes
/
TextFileTest.java
File metadata and controls
30 lines (26 loc) · 893 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
import java.io.*;
public class TextFileTest {
public TextFileTest() throws IOException {
}
public static void main(String[] args) throws IOException {
// 텍스트 파일에서 파일 읽기
try(BufferedReader in = new BufferedReader(
new FileReader("test.txt"))) {
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}}
catch (FileNotFoundException fe) {
System.out.println("FileNotFoundException 발생");
}
// in.close(); // 자원해지
// 파일 쓰기
try (BufferedWriter out = new BufferedWriter(
new FileWriter("output.txt"))) {
out.write("hello world");
} catch (FileNotFoundException fe) {
System.out.println("FileNotFoundException");
}
// out.close();
}
}