Here you can find the source of serializeObject(Object obj, String destPath)
Parameter | Description |
---|---|
Exception | an exception |
public static void serializeObject(Object obj, String destPath) throws IOException
//package com.java2s; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { /**/*from w w w. j a v a2 s.co m*/ * Try to save an object for quick reloading later. * * @throws Exception */ public static void serializeObject(Object obj, String destPath) throws IOException { if (obj == null) { throw new IllegalArgumentException("Cannot serialize a null object."); } FileOutputStream f; ObjectOutputStream s = null; try { f = new FileOutputStream(destPath, false); s = new ObjectOutputStream(f); s.writeObject(obj); s.close(); } catch (IOException e) { if (s != null) { s.close(); } e.printStackTrace(); throw e; } } }