Here you can find the source of serializeToFile(Object object, File file)
Parameter | Description |
---|---|
object | Object to serialize |
file | File to receive serialized copy |
Parameter | Description |
---|---|
IOException | an exception |
public static void serializeToFile(Object object, File file) throws IOException
//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(); } }