Home Tutorial Java Core Files Java file PrintWriter

 
 

Share on Google+Share on Google+
Java file PrintWriter
Posted on: April 26, 2006 at 12:00 AM
Advertisement
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.

Advertisement

Related Tags for Java file PrintWriter:


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.

Posted on: April 26, 2006

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com