Pages

program demonstrates the use of FileWriter class

->The following program demonstrates the use of FileWriter class.
import java.io.*;
class FileWrite
{
  public static void main(String args[]) throws Exception
  {
  FileWriter fw = new FileWriter(“file2.txt”,true);
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  System.out.println(“Enter some text “);
  String data = br.readLine();
  // convert data into equalent character array
  char ch[] = data.toCharArray();
  fw.write(ch);
  fw.close();
 } // end main

} // end class