Share on Google+Share on Google+

Java file 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:


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");

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


Posted on: April 26, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.