PrintStream 

Introduction

The Java.io.PrintStream class adds functionality to another output stream, the ability to print representations of various data values conveniently.

Class declaration

Following is the declaration for Java.io.PrintStream class −

public class PrintStream
   extends FilterOutputStream
      implements Appendable, Closeable

Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

Field

Following are the fields for Java.io.PrintStream class −

  • protected OutputStream out − This is the output stream to be filtered.

Class constructors

Sr.No.Constructor & Description
1PrintStream(File file)This creates a new print stream, without automatic line flushing, with the specified file.
2PrintStream(File file, String csn)This creates a new print stream, without automatic line flushing, with the specified file and charset.
3PrintStream(OutputStream out)This creates a new print stream.
4PrintStream(OutputStream out, boolean autoFlush)This creates a new print stream.
5PrintStream(OutputStream out, boolean autoFlush, String encoding)This creates a new print stream.
6PrintStream(String fileName)This creates a new print stream, without automatic line flushing, with the specified file name.
7PrintStream(String fileName, String csn)This creates a new print stream, without automatic line flushing, with the specified file name and charset.

Class methods

Sr.No.Method & Description
1PrintStream append(char c)This method appends the specified character to this output stream.
2PrintStream append(CharSequence csq)This method appends the specified character sequence to this output stream.
3PrintStream append(CharSequence csq, int start, int end)This method appends a subsequence of the specified character sequence to this output stream.
4boolean checkError()This method flushes the stream and checks its error state.
5protected void clearError()This method clears the internal error state of this stream.
6void close()This method closes the stream.
7void flush()This method flushes the stream.
8PrintStream format(Locale l, String format, Object… args)This method writes a formatted string to this output stream using the specified format string and arguments.
9PrintStream format(String format, Object… args)This method writes a formatted string to this output stream using the specified format string and arguments.
10void print(boolean b)This method prints a boolean value.
11void print(char c)This method prints a character.
12void print(char[] s)This method prints an array of characters.
13void print(double d)This method prints a double-precision floating-point number.
14void print(float f)This method prints a floating-point number.
15void print(int i)This method prints an integer.
16void print(long l)This method prints a long integer.
17void print(Object obj)This method prints an object.
18void print(String s)This method Prints a string.
19PrintStream printf(Locale l, String format, Object… args)This is a convenience method to write a formatted string to this output stream using the specified format string and arguments.
20PrintStream printf(String format, Object… args)This is a convenience method to write a formatted string to this output stream using the specified format string and arguments.
21void println()This method terminates the current line by writing the line separator string.
22void println(boolean x)This method prints a boolean and then terminate the line.
23void println(char x)This method prints a character and then terminate the line.
24void println(char[] x)This method prints an array of characters and then terminate the line.
25void println(double x)This method prints a double and then terminate the line.
26void println(float x)This method Prints a float and then terminate the line.
27void println(int x)This method prints an integer and then terminate the line.
28void println(long x)This method prints a long and then terminate the line.
29void println(Object x)This method prints an Object and then terminate the line.
30void println(String x)This method prints a String and then terminate the line.
31protected void setError()This method sets the error state of the stream to true.
32void write(byte[] buf, int off, int len)This method writes len bytes from the specified byte array starting at offset off to this stream.
33void write(int b)This method writes the specified byte to this stream.

Methods inherited

This class inherits methods from the following classes −

  • Java.io.FilterOutputStream
  • Java.io.Object

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *