get Serializable byte array and return an object - Android File Input Output

Android examples for File Input Output:Byte Array

Description

get Serializable byte array and return an object

Demo Code


//package com.java2s;

import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.ObjectInputStream;

public class Main {

    public static Object getSerializable(byte[] bytes) {
        Object obj = null;//  w w  w.j  a va2  s.  c o  m
        try {
            ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
            ObjectInputStream ois = new ObjectInputStream(bis);
            obj = ois.readObject();
            ois.close();
            bis.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        return obj;
    }
}

Related Tutorials