Here you can find the source of saveToFile(Serializable object, File file, boolean compress)
public static void saveToFile(Serializable object, File file, boolean compress)
//package com.java2s; // This file is part of MarMoT, which is licensed under GPLv3. import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.Serializable; import java.util.zip.GZIPOutputStream; public class Main { public static void saveToFile(Serializable object, String filepath) { saveToFile(object, new File(filepath), true); }//from w w w. j a v a2s. c om public static void saveToFile(Serializable object, File file, boolean compress) { try { OutputStream ostream = new FileOutputStream(file); if (compress) { ostream = new GZIPOutputStream(ostream); } ObjectOutputStream stream = new ObjectOutputStream(ostream); stream.writeObject(object); stream.close(); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } public static void saveToFile(Serializable object, File file) { saveToFile(object, file, true); } }