Java tutorial
//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(); OutputStream outStream = null; try { outStream = new BufferedOutputStream(new FileOutputStream(dest)); outStream.write((byte[]) oObject); } finally { if (outStream != null) { outStream.close(); } } } }