Here you can find the source of saveObject2File(final Serializable object, final File file)
public static void saveObject2File(final Serializable object, final File file)
//package com.java2s; //License from project: Apache License import java.io.*; import java.util.zip.DeflaterOutputStream; public class Main { public static void saveObject2File(final Serializable object, final File file) { try {//from w w w.j a v a 2 s. c o m saveObject2FileImpl(object, file); } catch (final Exception _exception) { throw new RuntimeException( "Problems saving object [" + object + "] to file [" + file + "]: " + _exception.getMessage(), _exception); } } private static void saveObject2FileImpl(final Serializable object, final File file) throws IOException { ObjectOutputStream output = null; try { 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(); } } } }