Java Object Serialize serialize(Object object, File file)

Here you can find the source of serialize(Object object, File file)

Description

Serialise a given object into a given file

License

Open Source License

Parameter

Parameter Description
object the object to serialize
file the file to serialize the object

Declaration

public static void serialize(Object object, File file) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;

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

import java.io.ObjectOutputStream;

public class Main {
    /**//from  www.j a v  a 2 s  . c  om
     * Serialise a given object into a given file
     * 
     * @param object
     *            the object to serialize
     * @param file
     *            the file to serialize the object
     */
    public static void serialize(Object object, File file) {
        try {

            FileOutputStream fos = new FileOutputStream(file);
            ObjectOutputStream oos = new ObjectOutputStream(fos);

            try {
                oos.writeObject(object);
                oos.flush();
            } finally {
                try {
                    oos.close();
                } finally {
                    fos.close();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. serialize(Object object)
  2. serialize(Object object)
  3. serialize(Object object)
  4. serialize(Object object)
  5. serialize(Object object, boolean zipped)
  6. serialize(Object object, File file)
  7. serialize(Object object, String fileName)
  8. serialize(Object object, String path)
  9. Serialize(Object serializableObject, String filePath)