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.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Main {

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

        byte[] cbuf = new byte[10];

        FileOutputStream out = new FileOutputStream("test.txt");
        ObjectOutputStream oout = new ObjectOutputStream(out);

        oout.writeUTF("Hello World from java2s.com");
        oout.flush();
        oout.close();
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt"));

        ois.read(cbuf, 0, 7);

        for (int i = 0; i < 7; i++) {
            System.out.print((char) cbuf[i]);
        }
        ois.close();
    }
}