Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

Java – The PrintWriter class

The PrintWriter is used to print the characters to the file in text form.

Declaration

class PrintWriter extends Writer

Constructors for PrintWriter (CLICK HERE)

Methods defined in PrintWriter (CLICK HERE)

Example

 import java.io.FileNotFoundException;
 import java.io.PrintWriter;

 class PrintWriterDemo 
 {
     public static void main(String args[]) throws FileNotFoundException 
     {
         PrintWriter pw = new PrintWriter("pwDemo.txt");
         pw.print("A, B, C are ");
         pw.print("Alphabets");
         pw.println();
         pw.println("P, Q, R are");
         pw.println("Alphabets");
         pw.write("L, M, N are ");
         pw.write("Alphabets");
         pw.flush();
         pw.close();
     }
 }

The text file “pwDemo.txt” is created in the current working dictionary.

Java Programming Language PrintWriter Class in File Handling

Leave a reply