Write string to file with FileWriter : FileWriter « File Input Output « Java

Write string to file with FileWriter

import java.io.FileWriter;

class FileWriterDemo {
  public static void main(String args[]) throws Exception {
    FileWriter fw = new FileWriter(args[0]);
    // Write strings to the file
    for (int i = 0; i < 12; i++) {
      fw.write("Line " + i + "\n");

    // Close file writer


Related examples in the same category

1.BufferedWriter out of FileWriter
2.Copy Characters between FileReader and FileWriter
3.Copy file character by character with FileReader and FileWriter
4.extends FilterWriter and extends FilterReader