Java Serialize serializeToFile(Object object, File file)

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

Description

Utility method to serialize an object to the given File.

License

Open Source License

Parameter

Parameter Description
object Object to serialize
file File to receive serialized copy

Exception

Parameter Description
IOException an exception

Declaration

public static void serializeToFile(Object object, File file) throws IOException 

Method Source Code

//package com.java2s;
/* IoUtils/*from   w w w.  j a va  2  s. c  om*/
 * 
 * Created on Dec 8, 2004
 *
 * Copyright (C) 2004 Internet Archive.
 * 
 * This file is part of the Heritrix web crawler (crawler.archive.org).
 * 
 * Heritrix is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * any later version.
 * 
 * Heritrix is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser Public License
 * along with Heritrix; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.io.BufferedOutputStream;

import java.io.File;

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

import java.io.ObjectOutputStream;

public class Main {
    /**
     * Utility method to serialize an object to the given File. 
     * 
     * @param object Object to serialize
     * @param file File to receive serialized copy
     * @throws IOException
     */
    public static void serializeToFile(Object object, File file) throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
        oos.writeObject(object);
        oos.close();
    }
}

Related

  1. serializeSafe(T obj)
  2. serializeShort(short value, byte[] outbuf, int offset)
  3. serializeString(File file, String string)
  4. serializeToBase64(Serializable object)
  5. serializeToFile(Object obj, String fileName)
  6. serializeToFile(Serializable s, String path)
  7. serializeToString(Object o)
  8. serializeToSurefireDirectory(final Class testClass, final Object object)
  9. serializeUnserialize(Object ob)