Turn System.out into a PrintWriter in Java

Description

The following code shows how to turn System.out into a PrintWriter.

Example


   /*w  w  w  .j a v a  2  s  .c  o  m*/
import java.io.PrintWriter;

public class Main {
  public static void main(String[] args) {
    PrintWriter out = new PrintWriter(System.out, true);
    out.println("Hello, world");
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip