Thursday, 10 October 2013

Write File Using FileWriter

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class WriteFileEx {

public static void main(String args[]) {

String data="THIS IS THE DATA TO WRITE IN THE FILE";

File file = new File("d:/java2.txt");
       FileWriter fr = null;
       try {
           fr = new FileWriter(file);
           fr.write(data);
       } catch (IOException e) {
           e.printStackTrace();
       }finally{
           try {
               fr.close();
           } catch (IOException e) {
               e.printStackTrace();
           }
       }
}

}

No comments:

Post a Comment