First of all, don't reinitialize the PrintStream object in every loop iteration.

To write to a file, simply call PrintStream's println method. You may not realise it, but when you print to the console, this is exactly what you are doing. System.out is a PrintStream object.

PrintStream out =
    new PrintStream(new File("stuff.txt"));
while (in.hasNext()) {
    String word = in.next();
    out.println(convert(word));
}
Answer from Jade on Stack Overflow
🌐
Programiz
programiz.com › java-programming › printstream
Java PrintStream (With Examples)
In this tutorial, we will learn about the Java PrintStream class and its print() and printf() methods with the help of examples to print output data.
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-print-elements-of-a-stream-in-java-8
How to print elements of a Stream in Java 8 - GeeksforGeeks
July 11, 2025 - Program 1: ... // Java code to ... "A", "Computer", "Portal"); // Print the stream using peek() // by providing a terminal operation count() stream.peek(s -> System.out.println(s)).count(); } }...
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › io › PrintStream.html
PrintStream (Java Platform SE 7 )
Appends the specified character to this output stream. An invocation of this method of the form out.append(c) behaves in exactly the same way as the invocation ... Java™ Platform Standard Ed. 7 ... Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › io › PrintStream.html
PrintStream (Java Platform SE 8 )
3 weeks ago - Appends the specified character to this output stream. An invocation of this method of the form out.append(c) behaves in exactly the same way as the invocation ... Java™ Platform Standard Ed. 8 ... Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
🌐
IncludeHelp
includehelp.com › java › how-to-print-elements-of-a-stream-in-java-8.aspx
How to print elements of a Stream in Java 8?
E:\Programs>javac PrintStreamE... main(String[] args) { // Here of() method of Stream interface is used to get the stream Stream stm = Stream.of("Java", "is", "a", "programming", "language"); // we are printing the stream by using forEach() method stm.forEach(System.out::println); ...
🌐
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 - Writes the specified byte to this stream. If the byte is a newline and automatic flushing is enabled then the flush method will be invoked. Note that the byte is written as given; to write a character that will be translated according to the platform's default character encoding, use the print(char) or println(char) methods.
Find elsewhere
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › io › PrintStream.html
PrintStream (Java SE 17 & JDK 17)
January 20, 2026 - Optionally, a PrintStream can be created so as to flush automatically; this means that the flush method of the underlying output stream is automatically invoked after a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written.
🌐
Tutorialspoint
tutorialspoint.com › java › io › java_io_printstream.htm
Java.io.PrintStream Class
Following are the fields for Java.io.PrintStream class − · protected OutputStream out − This is the output stream to be filtered.
🌐
Coding Shuttle
codingshuttle.com › home › handbooks › java programming handbook › java printstream class
Java PrintStream Class | Coding Shuttle
April 9, 2025 - You can create a PrintStream using various constructors: PrintStream ps = new PrintStream(String fileName); PrintStream ps = new PrintStream(File file); PrintStream ps = new PrintStream(OutputStream out);
🌐
Oracle
docs.oracle.com › en › java › javase › 26 › docs › api › java.base › java › io › PrintStream.html
PrintStream (Java SE 26 & JDK 26)
3 weeks ago - Optionally, a PrintStream can be created so as to flush automatically; this means that the flush method of the underlying output stream is automatically invoked after a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written.
🌐
MIT
web.mit.edu › java_v1.0.2 › www › javadoc › java.io.PrintStream.html
Class java.io.PrintStream
You can specify that the stream should be flushed every time a newline character is written. The top byte of 16 bit characters is discarded. Example: System.out.println("Hello world!"); System.out.print("x = "); System.out.println(x); System.out.println("y = " + y); PrintStream(OutputStream) ...
🌐
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(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 ... 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 FileNotFo
🌐
Tpoint Tech
tpointtech.com › java-printstream-class
Java PrintStream Class
March 17, 2025 - The following example demonstrates how to print formatted output using the printf() method of the PrintStream class. ... We request you to subscribe our newsletter for upcoming updates. ... We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
🌐
TechVidvan
techvidvan.com › tutorials › java-printstream-class
Java PrintStream Class with Examples - TechVidvan
May 6, 2024 - It then writes this formatted data to the output stream. if a newline character \n is written in the print stream if the println() method is called.
🌐
Jenkov
jenkov.com › tutorials › java-io › printstream.html
Java IO: PrintStream
September 3, 2015 - The PrintStream has a wide selection of constructors that enable you to connect it to a File, an OutputStream etc. You may be familiar with these two well-known PrintStream instances in Java: System.out and System.err . If you have every used ...
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Printstream Java Example - Java Code Geeks
January 19, 2021 - Download You can download the full source code of this example here: PrintStream Java Example
🌐
Java67
java67.com › 2022 › 11 › 10-examples-of-printstream-print.html
10 Examples of print(), println() and prinf() methods In Java - PrintStream | Java67
It can also represent a standard output stream that can be used to print text output onto the console. Another instance of the Printstream class is System.err. Printstream is also a byte outstream. It can convert all the output into bytes with the help of the specified encoding. This can be done using charset in the PrintStream() constructor invocation. Printstream in Java is also not limited to a console.