Home Tutorial Java Core Files Java file PrintWriter

 
 

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

Related Tags for Java file PrintWriter:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.