Java ObjectOutputStream Write saveObject(Object object, File file)

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

Description

Saves a raw Object to a file.

License

Open Source License

Parameter

Parameter Description
object The object to save.
file The file where the object will be stored.

Exception

Parameter Description
IOException an exception

Declaration

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

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 va 2 s . c  o  m*/
     * Saves a raw Object to a file.
     *
     * @param object The object to save.
     * @param file The file where the object will be stored.
     * @throws IOException
     */
    public static void saveObject(Object object, File file) throws IOException {
        if (!file.exists()) {
            file.getParentFile().mkdirs();
        }

        final ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
        oos.writeObject(object);
        oos.close();
    }
}

Related

  1. saveInSerFile(String filename, T object)
  2. saveObject(File file, Object o, boolean overwrite)
  3. saveObject(File file, Serializable obj)
  4. saveObject(Object o, File f)
  5. saveObject(Object obj, File file)
  6. saveObject(Object object, String filename)
  7. saveObject(Object object, String filename)
  8. saveObject(Object saveObject, File path)
  9. saveObject(Serializable obj, String url)