Java Serializable Serialize serializeObjectToFile(File targetFile, Serializable serializable)

Here you can find the source of serializeObjectToFile(File targetFile, Serializable serializable)

Description

serialize Object To File

License

Apache License

Declaration

public static void serializeObjectToFile(File targetFile, Serializable serializable) 

Method Source Code

//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) {

            }
        }
    }
}

Related

  1. serializeObject(Serializable cds)
  2. serializeObject(Serializable o)
  3. serializeObject(Serializable obj, String filename)
  4. serializeObject(Serializable ser)
  5. serializeObject(Serializable serializable)