Here you can find the source of deserialize(File file, Class
private static <T> T deserialize(File file, Class<T> clazz) throws IOException, ClassNotFoundException
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.util.zip.Inflater; import java.util.zip.InflaterInputStream; public class Main { private static <T> T deserialize(File file, Class<T> clazz) throws IOException, ClassNotFoundException { InputStream raw = new BufferedInputStream(new FileInputStream(file)); int compress = raw.read(); if (compress == 1) { raw = new InflaterInputStream(raw, new Inflater(true)); }// w w w . j ava 2 s. c o m T result; ObjectInputStream in = new ObjectInputStream(raw); try { result = clazz.cast(in.readObject()); } finally { in.close(); } return result; } }