Android Object Serialization objectToByte(Object obj)

Here you can find the source of objectToByte(Object obj)

Description

object To Byte

Declaration

public static byte[] objectToByte(Object obj) throws Exception 

Method Source Code

//package com.java2s;

import java.io.ByteArrayOutputStream;

import java.io.ObjectOutputStream;

public class Main {

    public static byte[] objectToByte(Object obj) throws Exception {
        ObjectOutputStream oos = null;
        try {//w  ww  .  j  a va 2 s.  c  o m
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(bos);
            oos.writeObject(obj);
            return bos.toByteArray();
        } finally {
            if (oos != null)
                oos.close();
        }
    }
}

Related

  1. writeObjectToFile(Object obj, String filePath, boolean append)
  2. writeQueueToFile(Queue list, String filePath)
  3. ObjectToByte(Serializable obj)
  4. obj2Bytes(Object obj)
  5. obj2Bytes(Object obj)
  6. getObjectFormFile(String filePath)