Here you can find the source of writeObjectToFile(Object oObject, File destDir, String filename)
public static void writeObjectToFile(Object oObject, File destDir, String filename) throws IOException
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; public class Main { public static void writeObjectToFile(Object oObject, File destDir, String filename) throws IOException { File dest = new File(destDir, filename); if (dest.exists()) dest.delete();/* ww w . j a v a2 s. c om*/ OutputStream outStream = null; try { outStream = new BufferedOutputStream(new FileOutputStream(dest)); outStream.write((byte[]) oObject); } finally { if (outStream != null) { outStream.close(); } } } }