Here you can find the source of writeObjectToFile(File fileLocation, Object obj)
public static void writeObjectToFile(File fileLocation, Object obj) throws IOException
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.util.zip.GZIPOutputStream; public class Main { public static void writeObjectToFile(File fileLocation, Object obj) throws IOException { OutputStream file = new FileOutputStream(fileLocation); OutputStream buffer = new GZIPOutputStream(file); try (ObjectOutput output = new ObjectOutputStream(buffer)) { output.writeObject(obj);// w w w . ja v a 2s. c o m } } }