Java tutorial
//package com.java2s; //License from project: Apache License 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 final void SaveObject(final String path, final Object saveObject) { FileOutputStream fileOutputStream = null; ObjectOutputStream objectOutputStream = null; File file = new File(path); try { if (!file.exists()) { file.createNewFile(); } fileOutputStream = new FileOutputStream(file); objectOutputStream = new ObjectOutputStream(fileOutputStream); objectOutputStream.writeObject(saveObject); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (objectOutputStream != null) { objectOutputStream.close(); } if (fileOutputStream != null) { fileOutputStream.close(); } } catch (IOException e) { e.printStackTrace(); } } } }