Write data to text file with Java



User Rating:  / 0
PoorBest 
Details
Category: Java
Created on Sunday, 29 April 2012 06:58
Last Updated on Thursday, 03 May 2012 14:20
Published on Sunday, 29 April 2012 06:58
Written by Administrator
Hits: 13574

Create text file and write data with java :

View source
/*
 * www.developerpages.gr
 * Create text file and write data
 */
package writetofile;
 
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
 
 
public class WriteToFile {
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       
        FileWriter outFile;
        try {
            outFile = new FileWriter("test.txt");
            PrintWriter out = new PrintWriter(outFile);
            out.println("www.developerpages.gr");
            out.println("---------------------");
            out.println("write Test data into text file ");
            out.close();        
        } catch (IOException ex) {
            Logger.getLogger(WriteToFile.class.getName()).log(Level.SEVEREnull, ex);
        }
 
   }
}