Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Formatter;

public class Main {

    public static void main(String[] args) throws FileNotFoundException {

        Formatter formatter = new Formatter(new FileOutputStream("generated/format.txt"));

        // format a new string
        String name = "from java2s.com";
        formatter.format("Hello %s !", name);

        // print the formatted string
        System.out.println(formatter);

        // flush the formatter. Here it does nothing.
        formatter.flush();
        System.out.println("Formatter Flushed.");
    }
}