Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.io.ObjectOutput;
import java.io.ObjectOutputStream;

public class Main {
    public static byte[] ObjectToByte(Object obj) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        ObjectOutput out = null;

        try {
            out = new ObjectOutputStream(bos);

            out.writeObject(obj);

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        byte[] Bytes = bos.toByteArray();

        return Bytes;

    }
}