File tree Expand file tree Collapse file tree
chapter04/src/main/java/io Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments