🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › io › PrintStream.html
PrintStream (Java Platform SE 8 )
3 weeks ago - All characters printed by a PrintStream are converted into bytes using the platform's default character encoding. The PrintWriter class should be used in situations that require writing characters rather than bytes. ... Creates a new print stream. This stream will not flush automatically. ... Creates a new print stream. ... autoFlush - A boolean; if true, the output buffer will be flushed whenever a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written
🌐
Programiz
programiz.com › java-programming › printstream
Java PrintStream (With Examples)
Note: The PrintStream class also has a feature of auto flushing. This means it forces the output stream to write all the data to the destination under one of the following conditions: if newline character \n is written in the print stream
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.io.printstream
PrintStream Class (Java.IO) | Microsoft Learn
A PrintStream adds functionality to another output stream, namely the ability to print representations of various data values conveniently.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › io › PrintStream.html
PrintStream (Java Platform SE 7 )
All characters printed by a PrintStream are converted into bytes using the platform's default character encoding. The PrintWriter class should be used in situations that require writing characters rather than bytes. ... Creates a new print stream. This stream will not flush automatically. ... Creates a new print stream. ... autoFlush - A boolean; if true, the output buffer will be flushed whenever a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › io › PrintStream.html
PrintStream (Java SE 11 & JDK 11 )
January 20, 2026 - Unlike other output streams, a PrintStream never throws an IOException; instead, exceptional situations merely set an internal flag that can be tested via the checkError method. Optionally, a PrintStream can be created so as to flush automatically; this means that the flush method is automatically ...
🌐
Oracle
docs.oracle.com › en › java › javase › 19 › docs › api › java.base › java › io › PrintStream.html
PrintStream (Java SE 19 & JDK 19)
December 12, 2022 - Creates a new print stream, without automatic line flushing, with the specified OutputStream. Characters written to the stream are converted to bytes using the default charset, or where out is a PrintStream, the charset used by the print stream.
🌐
Quora
quora.com › What-is-the-use-of-PrintStream-class-What-is-the-difference-between-using-System-out-print-and-PrintStream-Which-one-is-more-used-and-where-do-we-usually-use-PrintStream
What is the use of PrintStream class? What is the difference between using “System.out.print” and PrintStream? Which one is more used and where do we usually use PrintStream? - Quora
Answer (1 of 3): What is the use of PrintStream class? where do we usually use PrintStream? Inside the Java libraries there are 375 references to [code ]PrintStream[/code]. It is used a lot, everywhere where printed output needed it is realized using the [code ]PrintStream [/code]class. In trac...
🌐
Coding Shuttle
codingshuttle.com › home › handbooks › java programming handbook › java printstream class
Java PrintStream Class | Coding Shuttle
April 9, 2025 - The PrintStream class in Java is a specialized output stream used to print data in a human-readable format.
🌐
O'Reilly
oreilly.com › library › view › java-for-dummies › 9781118239742 › a64_07_9781118239742-ch04.html
PrintStream Class - Java For Dummies Quick Reference [Book]
June 5, 2012 - The PrintStream class is similar to the PrintWriter class in that it lets you write data to an output stream. PrintStream and PrintWriter have nearly identical methods. The primary difference is that PrintStream writes raw bytes in the machine’s ...
Author   Doug Lowe
Published   2012
Pages   288
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-io-printstream-class-java-set-1
Java.io.Printstream Class in Java | Set 1 - GeeksforGeeks
September 12, 2023 - 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 ...
Find elsewhere
🌐
Xplor
wiki.xplor.org › index.php
Print Streams - Xplor Wiki
A print stream is a file that contains a series of bytes that are intended to print or be displayed in a print-like setting. The print stream describes what text and/or images to place on paper or other physical medium. It also describes how the text and/ or images are to be placed on the medium.
🌐
Tutorialspoint
tutorialspoint.com › java › io › java_io_printstream.htm
Java.io.PrintStream Class
The Java.io.PrintStream class adds functionality to another output stream, the ability to print representations of various data values conveniently. Following is the declaration for Java.io.PrintStream class − Following are the fields for
🌐
Runestone Academy
runestone.academy › ns › books › published › javajavajava › ch1-system-print.html
1.7 From the Java Library: System and PrintStream
It contains a variety of print() and println() methods that can be used to print all of the various types of data we find in a Java program. A partial definition of PrintStream is shown in Figure 1.7.1.
🌐
CodeGym
codegym.cc › java blog › java io & nio › java printstream class
Java PrintStream Class
October 11, 2023 - The general purpose of the PrintStream class is to send information to some stream. This class has several constructors.
🌐
Oracle
docs.oracle.com › en › java › javase › 12 › docs › api › java.base › java › io › PrintStream.html
PrintStream (Java SE 12 & JDK 12 )
Unlike other output streams, a PrintStream never throws an IOException; instead, exceptional situations merely set an internal flag that can be tested via the checkError method. Optionally, a PrintStream can be created so as to flush automatically; this means that the flush method is automatically ...
🌐
Javatpoint
javatpoint.com › PrintStream-class
Java PrintStream class - javatpoint
The PrintStream class provides methods to write data to another stream. The PrintStream class automatically flushes the data so there is no need to call flush() method. Moreover, its methods doesn't throw IOException.
🌐
Oracle
docs.oracle.com › javame › 8.0 › api › cldc › api › java › io › PrintStream.html
PrintStream (Java(TM) ME Connected Limited Device Configuration, Version 8 (JSR360 Final Release))
All characters printed by a PrintStream are converted into bytes using the platform's default character encoding. ... Creates a new print stream. This stream will not flush automatically. ... Creates a new print stream. ... autoFlush - A boolean; if true, the output buffer will be flushed whenever a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written
Top answer
1 of 6
135

This might sound flippant, but PrintStream prints to an OutputStream, and PrintWriter prints to a Writer. Ok, I doubt I'll get any points for stating the obvious. But there's more.

So, what is the difference between an OutputStream and a Writer? Both are streams, with the primary difference being a OutputStream is a stream of bytes while a Writer is a stream of characters.

If an OutputStream deals with bytes, what about PrintStream.print(String)? It converts chars to bytes using the default platform encoding. Using the default encoding is generally a bad thing since it can lead to bugs when moving from one platform to another, especially if you are generating the file on one platform and consuming it on another.

With a Writer, you typically specify the encoding to use, avoiding any platform dependencies.

Why bother having a PrintStream in the JDK, since the primary intent is to write characters, and not bytes? PrintStream predates JDK 1.1 when Reader/Writer character streams were introduced. I imagine Sun would have deprecated PrintStream if only for the fact it is so widely used. (After all, you wouldn't want each call to System.out to generate a deprecated API warning! Also, changing the type from PrintStream to PrintWriter on the standard output streams would have broken existing applications.)

2 of 6
22

Since JDK 1.4 it's possible to specify the character encoding for a PrintStream. Thus, the differences between PrintStream and PrintWriter are only about auto flushing behavior and that a PrintStream cannot wrap a Writer.

🌐
Baeldung
baeldung.com › home › java › java io › printstream vs printwriter in java
PrintStream vs PrintWriter in Java | Baeldung
January 8, 2024 - However, we expect to see the autoFlushPrintWriter.txt file empty, although this is not guaranteed. After all, flushing could have happened during the execution of the program. If we want to force flushing when using PrintWriter, the code must meet all requirements we mentioned above, or we can add a line of code to flush the writer explicitly: ... In this article, we compared the two data stream classes PrintStream and PrintWriter.