Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.*;

public class Main {
    public static byte[] toByteArray(Object obj) {
        byte[] returnBytes = null;
        ByteArrayOutputStream byteArrayOutStream = new ByteArrayOutputStream();
        ObjectOutput objectOut = null;
        try {
            objectOut = new ObjectOutputStream(byteArrayOutStream);
            objectOut.writeObject(obj);
            returnBytes = byteArrayOutStream.toByteArray();
        } catch (java.io.IOException ioe) {
            return null;
        } finally {
            try {
                objectOut.close();
                byteArrayOutStream.close();
            } catch (java.io.IOException ioe) {

            }
        }
        return returnBytes;
    }
}