Java Object Serialize serialize(Object object, File file)

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

Description

serialize

License

Apache License

Declaration

public static void serialize(Object object, File file) 

Method Source Code

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

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import java.io.ObjectOutput;
import java.io.ObjectOutputStream;

import java.io.OutputStream;

public class Main {
    public static void serialize(Object object, File file) {
        try {/*from   w  w w . ja  v a2 s  .c  om*/
            serialize(object, new FileOutputStream(file));
        } catch (final FileNotFoundException e) {
            throw new IllegalArgumentException("File must exist.", e);
        }
    }

    public static void serialize(Object object, OutputStream outputStream) {
        try {
            final OutputStream buffer = new BufferedOutputStream(
                    outputStream);
            final ObjectOutput output = new ObjectOutputStream(buffer);
            try {
                output.writeObject(object);
            } finally {
                output.close();
            }
        } catch (final IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. serialize(Object object)
  2. serialize(Object object)
  3. serialize(Object object)
  4. serialize(Object object, boolean zipped)
  5. serialize(Object object, File file)
  6. serialize(Object object, String fileName)
  7. serialize(Object object, String path)
  8. Serialize(Object serializableObject, String filePath)
  9. serialize(Object state)