File & Directory
How to create easy text file
For working with files you need to use:
import java.io.*;
When the output file exists, it will be overriden.
File file = new File( "c:\\test.txt" ); try { /* create writer */ FileWriter writer = new FileWriter( file ); /* get string for new row */ String newRow = System.getProperty( "line.separator" ); /* write lines */ writer.write( "First row" + newRow ); writer.write( "Second row" + newRow ); writer.write( "One;Two;Three" + newRow ); /* close file */> writer.close(); } catch (IOException ex) { Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex); }
The line separator is OS specific char(s) sequence for separating text file lines.
The text output file looks like this:First row Second row One;Two;Three