Easy Tutorial
❮ Exception Catch Method Override ❯

Java Example - File Writing

Java Example

The following example demonstrates how to write content to a file using the write() method:

Example

/*
 author by tutorialpro.org 
 Main.java
 */

import java.io.*;

public class Main {
    public static void main(String[] args)  {
        try {
            BufferedWriter out = new BufferedWriter(new FileWriter("tutorialpro.txt"));
            out.write("tutorialpro.org");
            out.close();
            System.out.println("File created successfully!");
        } catch (IOException e) {
        }
    }
}

The output of the above code is:

File created successfully!

After successful creation, a file named "tutorialpro.txt" will be generated in the current directory with the string "tutorialpro.org" written into it.

Java Example

❮ Exception Catch Method Override ❯