Here you can find the source of deserialize(String path)
Parameter | Description |
---|---|
T | type of object |
path | path of file |
Parameter | Description |
---|---|
IOException | when IO error |
ClassNotFoundException | when deserializing wrong class |
public static <T> T deserialize(String path) throws IOException, ClassNotFoundException
//package com.java2s; //License from project: Mozilla Public License import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.util.zip.GZIPInputStream; public class Main { /**/*from w w w .j a v a 2 s . c o m*/ * Deserialize object. * * @param <T> type of object * @param path path of file * @return object * @throws IOException when IO error * @throws ClassNotFoundException when deserializing wrong class */ public static <T> T deserialize(String path) throws IOException, ClassNotFoundException { return deserialize(new FileInputStream(path)); } /** * Deserialize object. * * @param <T> type of object * @param in input stream * @return object * @throws IOException when IO error * @throws ClassNotFoundException when deserializing wrong classe */ @SuppressWarnings("unchecked") public static <T> T deserialize(InputStream in) throws IOException, ClassNotFoundException { try (ObjectInputStream ois = new ObjectInputStream(new GZIPInputStream(in))) { return (T) ois.readObject(); } } }