Java Object Deserialize from File deserialize(File file)

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

Description

Deserialize a serialized, compressed object at the file path provided.

License

Open Source License

Parameter

Parameter Description
file the file to read.

Exception

Parameter Description
IOException an exception
ClassNotFoundException an exception

Return

the deserialized data.

Declaration

public static Serializable deserialize(File file) throws IOException, ClassNotFoundException 

Method Source Code

//package com.java2s;
/**/*from   ww w.  j a  va2s.  c  o  m*/
 * This software is released as part of the Pumpernickel project.
 * 
 * All com.pump resources in the Pumpernickel project are distributed under the
 * MIT License:
 * https://raw.githubusercontent.com/mickleness/pumpernickel/master/License.txt
 * 
 * More information about the Pumpernickel project is available here:
 * https://mickleness.github.io/pumpernickel/
 */

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.Serializable;

import java.util.zip.GZIPInputStream;

public class Main {
    /**
     * Deserialize a serialized, compressed object at the file path provided.
     * 
     * See {@link #serialize(Serializable, File)}
     * 
     * @param file
     *            the file to read.
     * @return the deserialized data.
     * @throws IOException
     * @throws ClassNotFoundException
     */
    public static Serializable deserialize(File file) throws IOException, ClassNotFoundException {
        try (FileInputStream fileIn = new FileInputStream(file)) {
            try (GZIPInputStream zipIn = new GZIPInputStream(fileIn)) {
                try (ObjectInputStream objIn = new ObjectInputStream(zipIn)) {
                    return (Serializable) objIn.readObject();
                }
            }
        }
    }
}

Related

  1. deserialiseObject(File f)
  2. deserialization(String filePath)
  3. deserialize(File file)
  4. deserialize(File file)
  5. deserialize(File file)
  6. deserialize(File file)
  7. deserialize(File file, Class clazz)
  8. deserialize(final File file)
  9. deserialize(final String path)