Java Object Save writeObject(Object p_object, File p_outFile)

Here you can find the source of writeObject(Object p_object, File p_outFile)

Description

Writes an object to a file using object serialization.

License

Open Source License

Parameter

Parameter Description
p_object The object to write. (must support serialization)
p_outFile The file to write to

Return

The success status

Declaration

public static boolean writeObject(Object p_object, File p_outFile) 

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 {
    /**/*w  w  w . ja v  a2 s. c  om*/
     * Writes an object to a file using object serialization.
     * @param p_object The object to write. (must support serialization)
     * @param p_outFile The file to write to
     * @return The success status
     */
    public static boolean writeObject(Object p_object, File p_outFile) {
        try {
            FileOutputStream fStream = new FileOutputStream(p_outFile);
            ObjectOutputStream oObject = new ObjectOutputStream(fStream);

            oObject.writeObject(p_object);

            oObject.close();
            fStream.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
}

Related

  1. writeObject(Object obj, File path)
  2. writeObject(Object obj, ObjectOutput out)
  3. writeObject(Object object)
  4. writeObject(Object object, File destinationFile)
  5. writeObject(Object object, String path)
  6. writeObjectToFile(File file, Object o)
  7. writeObjectToFile(File file, Object obj)
  8. writeObjectToFile(final Object o, final File dir)
  9. writeObjectToFile(Object o, File file, boolean append)