Java Object Serialize serializeObject(Object obj, String destPath)

Here you can find the source of serializeObject(Object obj, String destPath)

Description

Try to save an object for quick reloading later.

License

Open Source License

Exception

Parameter Description
Exception an exception

Declaration

public static void serializeObject(Object obj, String destPath) throws IOException 

Method Source Code

//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;
        }
    }
}

Related

  1. serializeObject(final Serializable obj)
  2. serializeObject(Object data)
  3. serializeObject(Object myObject)
  4. serializeObject(Object o)
  5. serializeObject(Object obj)
  6. serializeObject(Object obj, String dir)
  7. serializeObject(Object object)
  8. serializeObject(Object object)
  9. serializeObject(Object object, File f)