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) {

        try {
            OutputStream os = new FileOutputStream("test.txt");
            OutputStreamWriter writer = new OutputStreamWriter(os);

            // create a new FileInputStream to read what we write
            FileInputStream in = new FileInputStream("test.txt");

            // write something in the file
            writer.write(70);

            // flush the stream
            writer.flush();

            // read what we write
            System.out.println((char) in.read());

            // close the stream
            writer.close();
            os.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}