Writer — 문자 출력 추상 클래스
Writer — 문자 출력 추상 클래스
Writer는 문자 스트림에 출력하는 작업을 위한 추상 클래스입니다. 하위 클래스가 반드시 구현해야 하는 메서드는 write(char[], int, int), flush(), close() 세 가지뿐입니다. 대부분의 하위 클래스는 더 높은 효율이나 추가 기능을 위해 이 클래스에 정의된 일부 메서드를 재정의합니다.
본문
이 클래스는 Appendable, Closeable, Flushable 인터페이스를 구현합니다.
public abstract class Writer extends Object
implements Appendable, Closeable, Flushable
필드
protected Object lock
lock— 이 스트림에 대한 동기화에 사용되는 객체입니다. 명시적으로 지정하지 않으면Writer자기 자신을 사용합니다.
생성자
protected Writer()
protected Writer(Object lock)
Writer()—lock이 자기 자신이 되는 기본 생성자입니다.Writer(Object lock)— 동기화에 사용할 객체를 지정하는 생성자입니다.
주요 메서드
public static Writer nullWriter()
public void write(int c) throws IOException
public void write(char[] cbuf) throws IOException
public abstract void write(char[] cbuf, int off, int len) throws IOException
public void write(String str) throws IOException
public void write(String str, int off, int len) throws IOException
public Writer append(CharSequence csq) throws IOException
public Writer append(CharSequence csq, int start, int end) throws IOException
public Writer append(char c) throws IOException
public abstract void flush() throws IOException
public abstract void close() throws IOException
write계열 메서드는 한 문자, 문자 배열, 문자열을 출력합니다.append계열 메서드는CharSequence를 덧붙이고 자기 자신(this)을 반환해 연결 호출(chaining)을 지원합니다.flush()는 버퍼에 남아 있는 데이터를 목적지로 강제로 씁니다.close()는 스트림을 닫고 관련 리소스를 해제합니다.nullWriter()는 모든 출력을 버리고 아무 동작도 하지 않는Writer를 반환합니다.