Here you can find the source of writeObjectToFile(Object obj, String filePath, boolean append)
public static void writeObjectToFile(Object obj, String filePath, boolean append)
//package com.java2s; 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 writeObjectToFile(Object obj, String filePath, boolean append) { if (obj == null || filePath == null || filePath.length() == 0) return; try {//from ww w . j a va2 s .com File file = new File(filePath); if (!file.exists()) { File parent = file.getParentFile(); if (!parent.exists()) parent.mkdirs(); boolean isSuc = file.createNewFile(); System.out.println("isSuc" + isSuc); } ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream(file, append)); oos.writeObject(obj); oos.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static void writeObjectToFile(Object obj, String filePath) { writeObjectToFile(obj, filePath, false); } }