Java Object Deserialize from File deserialize(String path)

Here you can find the source of deserialize(String path)

Description

Deserialize object.

License

Mozilla Public License

Parameter

Parameter Description
T type of object
path path of file

Exception

Parameter Description
IOException when IO error
ClassNotFoundException when deserializing wrong class

Return

object

Declaration

public static <T> T deserialize(String path) throws IOException, ClassNotFoundException 

Method Source Code


//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();
        }
    }
}

Related

  1. deserialize(String filePath)
  2. deserialize(String fName)
  3. deserialize(String fname)
  4. deserialize(String path)
  5. deserialize(String path)
  6. deserializeFromDisk(String filePath)
  7. deserializeFromFile(File file)
  8. deserializeFromFile(File file)
  9. deserializeFromFile(String path)