Tutorials Books About
Java Io

1 Java IO Tutorial
2 Java IO Overview
3 Java IO: Files
4 Java IO: Pipes
5 Java IO: Networking
6 Java IO: Byte & Char Arrays
7 Java IO:, System.out, and System.error
8 Java IO: Streams
9 Java IO: Input Parsing
10 Java IO: Readers and Writers
11 Java IO: Concurrent IO
12 Java IO: Exception Handling
13 Java IO: InputStream
14 Java IO: OutputStream
15 Java IO: FileInputStream
16 Java IO: FileOutputStream
17 Java IO: RandomAccessFile
18 Java IO: File
19 Java IO: PipedInputStream
20 Java IO: PipedOutputStream
21 Java IO: ByteArrayInputStream
22 Java IO: ByteArrayOutputStream
23 Java IO: FilterInputStream
24 Java IO: FilterOutputStream
25 Java IO: BufferedInputStream
26 Java IO: BufferedOutputStream
27 Java IO: PushbackInputStream
28 Java IO: SequenceInputStream
29 Java IO: DataInputStream
30 Java IO: DataOutputStream
31 Java IO: PrintStream
32 Java IO: ObjectInputStream
33 Java IO: ObjectOutputStream
34 Java IO: Serializable
35 Java IO: Reader
36 Java IO: Writer
37 Java IO: InputStreamReader
38 Java IO: OutputStreamWriter
39 Java IO: FileReader
40 Java IO: FileWriter
41 Java IO: PipedReader
42 Java IO: PipedWriter
43 Java IO: CharArrayReader
44 Java IO: CharArrayWriter
45 Java IO: BufferedReader
46 Java IO: BufferedWriter
47 Java IO: FilterReader
48 Java IO: FilterWriter
49 Java IO: PushbackReader
50 Java IO: LineNumberReader
51 Java IO: StreamTokenizer
52 Java IO: PrintWriter
53 Java IO: StringReader
54 Java IO: StringWriter

Java IO: PrintWriter

The PrintWriter class enables you to write formatted data to an underlying Writer. For instance, writing int, long and other primtive data formatted as text, rather than as their byte values.

Here is a simple example:

PrintWriter writer = new PrintWriter(writer);

writer.print((int) 123);
writer.print((float) 123.456);

writer.printf(Locale.UK, "Text + data: %1$", 123);    


The PrintWriter class contains the powerful format() and printf() methods (they do exactly the same, but the name "printf" is more familiar to C-programmers). These methods allow you to mix text and data in very advanced ways, using a formatting string. For more information about format() and printf() see the JavaDoc.

The PrintWriter has a wide selection of contructors that enable you to connect it to a File, an OutputStream, or a Writer.

Connect with me: Newsletter - Get all my free tips!