Java file PrintWriter


 

Java file PrintWriter

This section demonstrates you the use of class PrintWriter.

This section demonstrates you the use of class PrintWriter.

Java file PrintWriter

This section demonstrates you the use of class PrintWriter.

PrintWriter prints formatted representations of objects to a text-output stream. In other words, you can say it enables to write formatted data to a writer. It implements all of the print methods found in PrintStream and does not contain methods for writing bytes. For instance, writing int, long and other primitive data formatted as text.

It has a wide selection of constructors that enable you to connect it to a File, an Output Stream, or a Writer. It enables us to access the printXXX methods.

Here is the code:

import java.io.*;

public class FilePrintWriter {
	public static void main(String[] args) throws Exception {
		PrintWriter pw = new PrintWriter("c:/newfile.txt");
		pw.println("This is the use of PrintWriter class");
		pw.println(1234);
		pw.close();
	}
}

Through the above code, you can easily understand the concept of PrintWriter.

Ads