Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.*;

public class Main {

    public static void main(String[] args) {
        String s = "from java2s.com";

        Writer writer = new PrintWriter(System.out);

        try {
            // append a string
            writer.append(s);

            // flush the writer
            writer.flush();

            // append a new string
            writer.append("\nThis is an example");

            // flush and close the stream
            writer.close();

        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}