Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {

    public static void main(String[] args) {
        try {

            OutputStream os = new FileOutputStream("test.txt");

            InputStream is = new FileInputStream("test.txt");

            // write something
            os.write('A');

            // flush the stream
            os.flush();

            // close the stream but it does nothing
            os.close();

            // read what we wrote
            System.out.println((char) is.read());
            is.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }
}