Here you can find the source of serialize(Object obj, String file)
public static void serialize(Object obj, String file)
//package com.java2s; //License from project: Open Source License import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { public static void serialize(Object obj, String file) { try {/*from www. j a v a2s .com*/ int lastDash = Math.max(file.lastIndexOf('\\'), file.lastIndexOf('/')); if (lastDash != -1) new File(file.substring(0, lastDash)).mkdirs(); ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file))); out.writeObject(obj); out.flush(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }