Here you can find the source of serializeObjectToFile(File targetFile, Serializable serializable)
public static void serializeObjectToFile(File targetFile, Serializable serializable)
//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; import java.io.OutputStream; import java.io.Serializable; public class Main { public static void serializeObjectToFile(File targetFile, Serializable serializable) { FileOutputStream fileOutputStream = null; ObjectOutputStream objectOutputStream = null; try {/*from ww w. j av a 2s . co m*/ fileOutputStream = new FileOutputStream(targetFile); try { objectOutputStream = new ObjectOutputStream(fileOutputStream); objectOutputStream.writeObject(serializable); } catch (IOException e) { } } catch (FileNotFoundException e) { } finally { closeOutStream(objectOutputStream); closeOutStream(fileOutputStream); } } public static void closeOutStream(OutputStream outputStream) { if (outputStream != null) { try { outputStream.flush(); } catch (IOException e) { } try { outputStream.close(); } catch (IOException e) { } } } }