Here you can find the source of writeObject(Object data, String filename)
private static void writeObject(Object data, String filename) throws IOException
//package com.java2s; //License from project: LGPL import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { private static void writeObject(Object data, String filename) throws IOException { File file = new File(filename); if (!file.exists()) { file.getParentFile().mkdirs(); file.createNewFile();/* w w w. ja va 2 s. c o m*/ } FileOutputStream fileOut = new FileOutputStream(file); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(data); out.close(); fileOut.close(); } }