PrintStream과 PrintWriter
- 프린터와 유사하게 출력하는 print(), println(), printf() 메소드를 가진 보조 스트림
출처, 이것이 자바다
- PrintStream은 바이트 출력 스트림과 연결되고, PrintWriter는 문자 출력 스트림과 연결
출처, 이것이 자바다
package ch18.sec09;
import java.io.FileOutputStream;
import java.io.PrintStream;
/*
보조스트림 : 프린터와 유사하게 출력하는 기능
PrintStream : 바이트기반 스트림
PrintWriter : 문자기반 스트림
*/
public class PrintStreamExample {
public static void main(String[] args) throws Exception {
FileOutputStream fos = new FileOutputStream("C:/dev/temp/pristream.txt");
PrintStream ps = new PrintStream(fos);
//System.out.println(); out필드가 PrintStream데이터 타입이다.
ps.print("마치 ");
ps.println("프린터가 출력하는 것처럼");
ps.println("데이터를 출력합니다.");
ps.printf("| %6d | %-10s | %10s", 1, "홍길동", "도적");
ps.printf("| %6d | %-10s | %10s", 2, "손흥민", "축구선수");
ps.flush();
ps.close();
}
}