Here you can find the source of serialize(Serializable obj, String fileName)
public static void serialize(Serializable obj, String fileName)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static void serialize(Serializable obj, String fileName) { ObjectOutputStream oos = null; try {/*from w ww. j a v a 2 s. c o m*/ FileOutputStream out = new FileOutputStream(fileName); oos = new ObjectOutputStream(out); oos.writeObject(obj); } catch (Exception e) { throw new RuntimeException(e); } finally { if (oos != null) { try { oos.close(); } catch (IOException e) { e.printStackTrace(); } } } } public static byte[] serialize(Serializable obj) { ObjectOutputStream oos = null; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); oos = new ObjectOutputStream(out); oos.writeObject(obj); return out.toByteArray(); } catch (Exception e) { throw new RuntimeException(e); } finally { if (oos != null) { try { oos.close(); } catch (IOException e) { e.printStackTrace(); } } } } }