Java Object Serialize serialize(T t, String filename)

Here you can find the source of serialize(T t, String filename)

Description

Serialize t object

License

Open Source License

Parameter

Parameter Description
T a parameter
t a parameter
filename a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static <T extends Serializable> void serialize(T t,
        String filename) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectOutputStream;

import java.io.Serializable;

public class Main {
    /**/* ww  w .j a va 2 s . c  om*/
     * Serialize t object
     * @param <T>
     * 
     * @param t
     * @param filename
     * @throws IOException
     */
    public static <T extends Serializable> void serialize(T t,
            String filename) throws IOException {
        ObjectOutputStream oos = null;

        try {
            final FileOutputStream fichier = new FileOutputStream(filename);
            oos = new ObjectOutputStream(fichier);
            oos.writeObject(t);

            oos.flush();
        } catch (final java.io.IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (oos != null) {
                    oos.flush();
                    oos.close();
                }
            } catch (final IOException ex) {
                ex.printStackTrace();
            }
        }
    }
}

Related

  1. serialize(T obj)
  2. serialize(T object)
  3. serialize(T object)
  4. serialize(T object)
  5. serialize(T t)
  6. serialize(T t, String path)
  7. serialize(T toSerialize)
  8. serialized(final Object item)
  9. serialized(Object o)