Android Object Serialization obj2Bytes(Object obj)

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

Description

obj Bytes

Declaration

public static byte[] obj2Bytes(Object obj) 

Method Source Code

//package com.java2s;

import java.io.ByteArrayOutputStream;

import java.io.ObjectOutputStream;

public class Main {

    public static byte[] obj2Bytes(Object obj) {
        byte[] result = null;

        try {//  w w w  .  j  a  v  a2 s .c  o m
            ByteArrayOutputStream bo = new ByteArrayOutputStream();
            ObjectOutputStream oo = new ObjectOutputStream(bo);
            oo.writeObject(obj);
            result = bo.toByteArray();
            bo.close();
            oo.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }
}

Related

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