package edu.exam14.ex09buffer_writer;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Scanner;

/*중간창고역할 Filter 클래스
I/O 속도 향상
BufferedInputStream
BufferedOutputStream
<->
BufferedReader
BufferedWriter*/

public class StringBufferWriter {

	public static void main(String[] args) throws IOException {

		Writer out = new FileWriter("String.txt");
		BufferedWriter bOut = new BufferedWriter(out);
		Scanner sc = new Scanner(System.in);

		while (true) {

			System.out.println("입력>>");
			String str = sc.next();
			if (str.equals("exit"))
				break;
			bOut.write(str);	//2단계 기록하기
			bOut.newLine();// 파일에서 한칸 아래로 개행할 때

		}
		bOut.close();	//3단계 스트림 닫기
		sc.close();
	}
}
package edu.exam14.ex10buffer_reader;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

public class StringBufferReader {
	public static void main(String[] args) throws IOException {
		Reader in = new FileReader("String.txt");	//다리
		BufferedReader bin = new BufferedReader(in);	//창고
		
		while(true) {
			String str = bin.readLine();	//개행문자 전까지 읽는다(개행문자는 빼고)
			if(str ==null)
				break;
			System.out.println(str);			
		}
		bin.close();
	}
}

'JAVA > java 예제' 카테고리의 다른 글

PrintWriterStream 예제  (0) 2020.01.29
Char Writer/Reader Stream 예제  (0) 2020.01.29
DataBufferFilterStream 예제  (0) 2020.01.29
BufferedFileStream 예제  (0) 2020.01.29
DataFilterStream 예제  (0) 2020.01.29

+ Recent posts