Here you can find the source of deserialize(String filename)
Parameter | Description |
---|---|
T | a parameter |
filename | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
@SuppressWarnings("unchecked") public static <T extends Serializable> T deserialize(String filename) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.FileInputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serializable; public class Main { /**/* w w w . j a v a2s . c o m*/ * @param <T> * @param filename * @return a T object read in the file passed in parameter * @throws IOException */ @SuppressWarnings("unchecked") public static <T extends Serializable> T deserialize(String filename) throws IOException { ObjectInputStream ois = null; T t = null; try { final FileInputStream fichier = new FileInputStream(filename); ois = new ObjectInputStream(fichier); t = (T) ois.readObject(); } catch (final java.io.IOException e) { e.printStackTrace(); } catch (final ClassNotFoundException e) { e.printStackTrace(); } finally { if (ois != null) { ois.close(); } if (t == null) { throw new IOException( "error when deserialisation (T) object"); } } return t; } }