Skip to content

Commit f791cda

Browse files
committed
6일차 io - 2
1 parent 96be5b2 commit f791cda

3 files changed

Lines changed: 88 additions & 8 deletions

File tree

‎.idea/workspace.xml‎

Lines changed: 13 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package io;
2+
3+
import java.io.BufferedOutputStream;
4+
import java.io.FileNotFoundException;
5+
import java.io.FileOutputStream;
6+
import java.io.IOException;
7+
8+
public class BufferedOutputStreamTest {
9+
public static void main(String[] args) {
10+
BufferedOutputStream bos = null;
11+
12+
try {
13+
// 기반 스트림
14+
FileOutputStream fis = new FileOutputStream("hello.txt");
15+
16+
// 보조 스트림
17+
bos = new BufferedOutputStream(fis);
18+
19+
//for(int i = 'a'; i <= 'z'; i++)
20+
for(int i = 97; i <= 122; i++) {
21+
bos.write(i);
22+
}
23+
} catch (FileNotFoundException e) {
24+
System.out.println("File Not Found: " + e);
25+
} catch (IOException e) {
26+
System.out.println("error: " + e);
27+
} finally {
28+
try {
29+
if(bos != null) {
30+
bos.close();
31+
}
32+
} catch (IOException e) {
33+
e.printStackTrace();
34+
}
35+
}
36+
}
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package io;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileNotFoundException;
5+
import java.io.FileReader;
6+
import java.io.IOException;
7+
8+
public class BufferedReaderTest {
9+
10+
public static void main(String[] args) {
11+
BufferedReader br = null;
12+
13+
try {
14+
// 기반 스트림
15+
FileReader fr = new FileReader("./src/main/java/io/FileReaderTest.java");
16+
17+
// 보조 스트림
18+
br = new BufferedReader(fr);
19+
20+
String line = null;
21+
while((line = br.readLine()) != null) {
22+
System.out.println(line);
23+
}
24+
} catch (FileNotFoundException e) {
25+
System.out.println("File Not Found:" + e);
26+
} catch (IOException e) {
27+
System.out.println("error:" + e);
28+
} finally {
29+
try {
30+
if(br != null) {
31+
br.close();
32+
}
33+
} catch (IOException e) {
34+
e.printStackTrace();
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)