Java Object Save writeObject(File f, Serializable obj)

Here you can find the source of writeObject(File f, Serializable obj)

Description

Serializes an object to a file, masking out annoying exceptions.

License

Open Source License

Parameter

Parameter Description
f File to write to
obj Object to serialize

Declaration

public static void writeObject(File f, Serializable obj) 

Method Source Code


//package com.java2s;
/* Copyright (C) 2003 Univ. of Massachusetts Amherst, Computer Science Dept.
   This file is part of "MALLET" (MAchine Learning for LanguagE Toolkit).
   http://www.cs.umass.edu/~mccallum/mallet
   This software is provided under the terms of the Common Public License,
   version 1.0, as published by http://www.opensource.org.  For further
   information, see the file `LICENSE' included with this distribution. */

import java.io.*;

public class Main {
    /**/*from   w w  w .ja v  a  2  s. com*/
     * Serializes an object to a file, masking out annoying exceptions.
     *  Any IO exceptions are caught, and printed to standard error.
     *  Consider using {@link #writeGzippedObject(java.io.File, java.io.Serializable)}
     *  instead, for that method will compress the serialized file, and it'll still
     * be reaoable by {@link #readObject}.
     * @param f File to write to
     * @param obj Object to serialize
     * @see #writeGzippedObject(java.io.File, java.io.Serializable)
     */
    public static void writeObject(File f, Serializable obj) {
        try {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
            oos.writeObject(obj);
            oos.close();
        } catch (IOException e) {
            System.err.println("Exception writing file " + f + ": " + e);
        }
    }
}

Related

  1. writeObject(File f, Object obj)
  2. writeObject(File file, Object obj)
  3. writeObject(File file, Object object)
  4. writeObject(File file, Object object)
  5. writeObject(File file, Object object)