Java Class Load from File deserialize(Class clazz, File file)

Here you can find the source of deserialize(Class clazz, File file)

Description

deserialize

License

Apache License

Declaration

public static <T extends Serializable> T deserialize(Class<T> clazz, File file)
            throws FileNotFoundException, IOException, ClassNotFoundException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;
import java.io.ObjectInputStream;

import java.io.Serializable;

public class Main {
    public static <T extends Serializable> T deserialize(Class<T> clazz, File file)
            throws FileNotFoundException, IOException, ClassNotFoundException {
        ObjectInputStream ois = null;
        try {//from ww w  . j a  v  a  2s  .com
            ois = new ObjectInputStream(new FileInputStream(file));
            return (T) ois.readObject();
        } finally {
            if (ois != null) {
                ois.close();
            }
        }
    }
}

Related

  1. deserialize(Class expectedType, byte[] data)
  2. deserialize(Class classOfT, byte[] bytes)
  3. deserialize(Class clazz, InputStream in)
  4. deserialize(Class type, @Nullable byte[] objectBytes)