The most enhanced writer for writing character data to the file is PrintWriter.

Constructors
  1. PrintWriter pw = new PrintWriter(String fname)
  2. PrintWriter pw = new PrintWriter(File f)
  3. PrintWriter pw = new PrintWriter(Writer w)
Important methods
  1. write(int ch)
  2. write(char [] ch)
  3. write(String s)
  4. print(int i)
    print(double d)
    print(char ch)
    print(Boolean b)
    print(char ch[])
  5. void flush()
  6. close()

Example:

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class PrintWriterDemo {

	
	public static void main(String[] args) throws IOException{
		FileWriter fw = new FileWriter("java2learn.txt");
		PrintWriter out = new PrintWriter(fw);
		out.write(97);
		out.println(100);
		out.println(true);
		out.println('c');
		out.println("JAVA");
		out.flush();
		out.close();
	}
}