Here you can find the source of serialize(T t, String filename)
Parameter | Description |
---|---|
T | a parameter |
t | a parameter |
filename | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static <T extends Serializable> void serialize(T t, String filename) throws IOException
//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(); } } } }