PrintStream은 다른 출력 스트림에 기능, 즉 다양한 데이터 값의 표현을 편리하게 인쇄하는 기능을 추가합니다. 다른 출력 스트림과 달리 PrintStream은 IOException을 발생시키지 않습니다. 대신 예외적인 상황은 checkError 메소드를 통해 테스트할 수 있는 내부 플래그를 설정하기만 하면 됩니다. 선택적으로 PrintStream을 생성하여 자동으로 플러시할 수 있습니다. PrintStream에 의해 인쇄된 모든 문자는 플랫폼의 기본 문자 인코딩을 사용하여 바이트로 변환됩니다. PrintWriter 클래스는 바이트가 아닌 문자를 써야 하는 상황에서 사용해야 합니다. 클래스 선언 public class PrintStream extends FilterOutputStream implements Appendable Closeable
필드 protected OutputStream out:This is the output stream to be filtered.
생성자 및 설명 | PrintStream(파일 파일): | 지정된 파일을 사용하여 자동 라인 플러시 없이 새 인쇄 스트림을 만듭니다.
| PrintStream(파일 파일 문자열 csn) : | 지정된 파일 및 문자 세트를 사용하여 자동 줄 플러시 없이 새 인쇄 스트림을 만듭니다.
| PrintStream(OutputStream 출력) : | 새 인쇄 스트림을 만듭니다.
| PrintStream(OutputStream 출력 부울 autoFlush): | 새 인쇄 스트림을 만듭니다.
| PrintStream(OutputStream 출력 부울 autoFlush 문자열 인코딩) | : 새 인쇄 스트림을 생성합니다.
| PrintStream(문자열 파일 이름) : | 지정된 파일 이름으로 자동 라인 플러시 없이 새 인쇄 스트림을 만듭니다.
| PrintStream(문자열 파일명 문자열 csn) : | 지정된 파일 이름과 문자 집합을 사용하여 자동 줄 플러시 없이 새 인쇄 스트림을 만듭니다. 행동 양식: | PrintStream 추가(문자 c) : | Appends the specified character to this output stream. Syntax : public PrintStream append(char c) Parameters: c - The 16-bit character to append Returns: This output stream
| PrintStream 추가(CharSequence csq int start int end): | Appends the specified character sequence to this output stream. Syntax : public PrintStream append(CharSequence csq int start int end) Parameters: csq - The character sequence from which a subsequence will be appended. start - The index of the first character in the subsequence end - The index of the character following the last character in the subsequence Returns: This output stream Throws: IndexOutOfBoundsException
| PrintStream 추가(CharSequence csq) : | Appends a subsequence of the specified character sequence to this output stream. Syntax : public PrintStream append(CharSequence csq) Parameters: csq - The character sequence to append. Returns: This output stream
| 부울 checkError(): | Flushes the stream and checks its error state. Syntax : public boolean checkError() Returns: true if and only if this stream has encountered an IOException other than InterruptedIOException or the setError method has been invoked
| 보호된 무효 ClearError(): | Clears the internal error state of this stream. Syntax : protected void clearError()
| 무효 닫기() : | Closes the stream. Syntax : public void close() Overrides: close in class FilterOutputStream
| 무효 플러시(): | Flushes the stream. Syntax : public void flush() Overrides: flush in class FilterOutputStream
| PrintStream 형식(로케일 l 문자열 형식 개체... args): | Writes a formatted string to this output stream using the specified format string and arguments. Syntax : public PrintStream format(Locale l String format Object... args) Parameters: l - The locale to apply during formatting. If l is null then no localization is applied. format - A format string as described in Format string syntax args - Arguments referenced by the format specifiers in the format string. The number of arguments is variable and may be zero. Returns: This output stream Throws: IllegalFormatException NullPointerException
| PrintStream 형식(문자열 형식 개체... args): | Writes a formatted string to this output stream using the specified format string and arguments. Syntax : public PrintStream format(String format Object... args) Parameters : format - A format string as described in Format string syntax args - Arguments referenced by the format specifiers in the format string. The number of arguments is variable and may be zero. Returns: This output stream Throws: IllegalFormatException NullPointerException
| 무효 인쇄(부울 b): | Prints a boolean value. Syntax : public void print(boolean b)
| 무효 인쇄(문자 c): | Prints a character. Syntax : public void print(char c)
| 무효 인쇄(char[] s): | Prints an array of characters. Syntax : public void print(char[] s)
| 무효 인쇄(더블 d) : | Prints a double-precision floating-point number. Syntax : public void print(double b)
| 무효 인쇄(float f): | Prints a floating-point number. Syntax : public void print(float f)
| 무효 인쇄(int i): | Prints an integer. Syntax : public void print(int i)
| 무효 인쇄(긴 l): | Prints a long integer. Syntax : public void print(long l)
| 무효 인쇄(객체 obj) : | Prints an object. Syntax : public void print(Object obj)
| 무효 인쇄(문자열 s): | Prints a string. Syntax : public void print(String s)
Java import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintStream; import java.util.Locale; //Java program to demonstrate PrintStream methods class Printstream { public static void main(String args[]) throws FileNotFoundException { FileOutputStream fout=new FileOutputStream('file.txt'); //creating Printstream obj PrintStream out=new PrintStream(fout); String s='First'; //writing to file.txt char c[]={'G''E''E''K'}; //illustrating print(boolean b) method out.print(true); //illustrating print(int i) method out.print(1); //illustrating print(float f) method out.print(4.533f); //illustrating print(String s) method out.print('GeeksforGeeks'); out.println(); //illustrating print(Object Obj) method out.print(fout); out.println(); //illustrating append(CharSequence csq) method out.append('Geek'); out.println(); //illustrating checkError() method out.println(out.checkError()); //illustrating format() method out.format(Locale.UK 'Welcome to my %s program' s); //illustrating flush method out.flush(); //illustrating close method out.close(); } } Note: The output might not be visible on online IDE as it is not able to read the file. 산출: true14.533GeeksforGeeks java.io.FileOutputStream@1540e19dGeek false Welcome to my First program
다음 기사: Java의 Java.io.Printstream 클래스 | 세트 2 퀴즈 만들기