Here you can find the source of saveObject2FileImpl(final Serializable object, final File file)
private static void saveObject2FileImpl(final Serializable object, final File file) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; import java.util.zip.DeflaterOutputStream; public class Main { private static void saveObject2FileImpl(final Serializable object, final File file) throws IOException { ObjectOutputStream output = null; try {//from w w w .ja v a 2s. c o m output = new ObjectOutputStream( new BufferedOutputStream(new DeflaterOutputStream(new FileOutputStream(file)), 1024 * 1024)); output.writeObject(object); output.flush(); output.close(); output = null; } finally { if (output != null) { output.close(); } } } }