public static File writeObjectToFile ( final Object o , final String fileName ) throws IOException { final File outFile = new File ( fileName ) ; OutputStream outputStream = new FileOutputStream ( outFile ) ; if ( fileName . endsWith ( ".gz" ) ) { outputStream = new GZIPOutputStream ( outputStream ) ; } outputStream = new BufferedOutputStream ( outputStream ) ; final ObjectOutputStream oos = new ObjectOutputStream ( outputStream ) ; oos . writeObject ( o ) ; oos . close ( ) ; return outFile ; }
Serialize java object to a file .