Java tutorial
//package com.java2s; //License from project: Apache License import java.io.FileOutputStream; import java.io.ObjectOutputStream; public class Main { public static boolean writeFileByObject(String fileName, Object object) { try { FileOutputStream fos = new FileOutputStream(fileName); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(object); oos.flush(); oos.close(); fos.close(); return true; } catch (Exception e) { e.printStackTrace(); return false; } } }