Here you can find the source of saveObjectToFile(final Object object, final String fileName)
public static void saveObjectToFile(final Object object, final String fileName)
//package com.java2s; //License from project: Open Source License import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { public static void saveObjectToFile(final Object object, final String fileName) { try {/*from w w w . j av a 2 s .co m*/ // TODO: this code could be optimized in a way that a new method is provide for sets of // strings where only the new strings are appended to the file FileOutputStream fileOutputStream = new FileOutputStream(fileName); ObjectOutputStream oos = new ObjectOutputStream(fileOutputStream); oos.writeObject(object); oos.flush(); oos.close(); } catch (IOException e) { throw new RuntimeException("Could not save '" + object + "' to file '" + fileName + "': " + e); } } }