Android examples for File Input Output:Object Serialization
Return byte array of serializable object
/*//from w w w. j a va 2 s . com * File: $RCSfile: ObjectUtilities.java,v $ * * Copyright (c) 2009 Kewill, * * All Rights Reserved. * * This software is the confidential and proprietary information * of Kewill ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered * into with Kewill. */ //package com.java2s; import java.io.*; public class Main { /** * Return byte array of serializable object * * @param object serializable object * @return <code>byte[]</code> * @throws java.io.IOException <code>java.io.IOException</code> */ public static byte[] getObjectByteArray(Serializable object) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(object); oos.close(); return bos.toByteArray(); } }