Java ObjectOutputStream Write saveObject(Object object, String filename)

Here you can find the source of saveObject(Object object, String filename)

Description

Stores a Serializable Object.

License

Open Source License

Parameter

Parameter Description
object a parameter
filename a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void saveObject(Object object, String filename) throws IOException 

Method Source Code


//package com.java2s;
import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;

public class Main {
    /**/*from  w  w  w . ja v a  2  s  .  c o m*/
     * Stores a Serializable Object.
     * 
     * @param object
     * @param out
     * 
     * @throws IOException
     */
    public static void saveObject(Object object, OutputStream out) throws IOException {
        if (!(object instanceof Serializable))
            throw new IllegalArgumentException("The object is not Serializable!");

        new ObjectOutputStream(out).writeObject(object);
    }

    /**
     * Stores a Serializable Object.
     * 
     * @param object
     * @param filename
     * 
     * @throws IOException
     */
    public static void saveObject(Object object, String filename) throws IOException {
        saveObject(object, new FileOutputStream(filename));
    }

    /**
     * Stores a Serializable Object.
     * 
     * @param object
     * @param file
     * 
     * @throws IOException
     */
    public static void saveObject(Object object, File file) throws IOException {
        saveObject(object, new FileOutputStream(file));
    }
}

Related

  1. saveObject(File file, Object o, boolean overwrite)
  2. saveObject(File file, Serializable obj)
  3. saveObject(Object o, File f)
  4. saveObject(Object obj, File file)
  5. saveObject(Object object, File file)
  6. saveObject(Object object, String filename)
  7. saveObject(Object saveObject, File path)
  8. saveObject(Serializable obj, String url)
  9. saveObject(String filename, Object obj)