Java Object Save writeObject(Object object, File destinationFile)

Here you can find the source of writeObject(Object object, File destinationFile)

Description

Writes an object to the destination file.

License

Apache License

Parameter

Parameter Description
object the object
destinationFile the destination file

Exception

Parameter Description
IOException exception thrown whenever an error occurred whilewriting the file

Declaration

public static void writeObject(Object object, File destinationFile)
        throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    /**//from w  w  w.j  a  v  a 2 s .  c om
     * Writes an object to the destination file.
     *
     * @param object the object
     * @param destinationFile the destination file
     * @throws IOException exception thrown whenever an error occurred while
     * writing the file
     */
    public static void writeObject(Object object, File destinationFile)
            throws IOException {

        FileOutputStream fos = new FileOutputStream(
                destinationFile.getAbsoluteFile());
        try {
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            try {
                ObjectOutputStream oos = new ObjectOutputStream(bos);
                try {
                    oos.writeObject(object);
                } finally {
                    oos.close();
                }
            } finally {
                bos.close();
            }
        } finally {
            fos.close();
        }
    }
}

Related

  1. writeObject(Object o, File path)
  2. writeObject(Object o, ObjectOutput dos)
  3. writeObject(Object obj, File path)
  4. writeObject(Object obj, ObjectOutput out)
  5. writeObject(Object object)
  6. writeObject(Object object, String path)
  7. writeObject(Object p_object, File p_outFile)
  8. writeObjectToFile(File file, Object o)
  9. writeObjectToFile(File file, Object obj)