Java Object Deserialize from File deserialize(final String path)

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

Description

Convenience method for deserializing an object from a file.

License

Open Source License

Return

the object obtained from the file.

Declaration

public static Object deserialize(final String path) throws ClassNotFoundException, IOException 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    /**/*www  .j a va  2s.c o m*/
     * <p>Convenience method for deserializing an object from a file.</p>
     *
     * @return the object obtained from the file.
     */
    public static Object deserialize(final String path) throws ClassNotFoundException, IOException {
        Object result;
        FileInputStream inputStream = new FileInputStream(path);
        ObjectInputStream objectInputStream = null;
        try {
            objectInputStream = new ObjectInputStream(inputStream);
            result = objectInputStream.readObject();
        } catch (IOException e) { // be sure to release input stream lock (at some point couldn't delete file)
            inputStream.close();
            if (objectInputStream != null)
                objectInputStream.close();
            throw e;
        } catch (ClassNotFoundException e) {
            objectInputStream.close();
            throw e;
        }
        objectInputStream.close();
        return result;
    }
}

Related

  1. deserialize(File file)
  2. deserialize(File file)
  3. deserialize(File file)
  4. deserialize(File file, Class clazz)
  5. deserialize(final File file)
  6. deserialize(String filename)
  7. deserialize(String fileName)
  8. deserialize(String filename)
  9. deserialize(String filePath)