Here you can find the source of writeObjectToFile(Object obj, String path)
public static void writeObjectToFile(Object obj, String path)
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; public class Main { public static void writeObjectToFile(Object obj, String path) { writeObjectToFile(obj, new File(path)); }// w w w .j a v a 2s . c o m public static void writeObjectToFile(Object obj, File path) { FileOutputStream out = null; try { out = new FileOutputStream(path); writeObjectToFile(obj, out); } catch (Exception ex) { } finally { try { out.close(); } catch (Exception ex) { } } } public static void writeObjectToFile(Object obj, OutputStream out) { ObjectOutputStream objOut = null; try { objOut = new ObjectOutputStream(out); objOut.writeObject(obj); } catch (Exception ex) { } finally { try { objOut.close(); } catch (Exception ex) { } } } }