FileWriterDemo.java Source code

Java tutorial

Introduction

Here is the source code for FileWriterDemo.java

Source

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
        fw.close();
    }
}