JAVA/IO
자바(버퍼드) BufferedIO_Test01 예제
미눅스[멘토]
2023. 6. 24. 13:26
728x90
package kr.or.ddit.basic;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
public class BufferedIOTest01 {
public static void main(String[] args) {
//입출력의 성능 향상을 위해서 Buffered스트림을 사용한다.
//출력용 buffered스트림 사용 예제
try {
FileOutputStream fout = new FileOutputStream("d:/D_Other/bufferTest.txt");
//버퍼의 크기가 5인 Buffered스트림 객체 생성
BufferedOutputStream bout = new BufferedOutputStream(fout, 5);
for(int i='1'; i<='9'; i++) {
bout.write(i);
}
bout.flush(); // 버퍼에 남아 있는 데이터를 모두 출력 장치로 출력 시킨다.
// fout.close();
bout.close(); // 보조 스트림을 닫으면 보조스트림에서 사용한 기반이 되는 스크림도 자동으로 닫힌다.
// 버퍼 스트림의 close()메소드에는 flush()기능이 포함되어 있다.
System.out.println("작업 끝...");
} catch (Exception e) {
// TODO: handle exception
}
}
}