Java Object Deserialize from File Deserialize(String filePath)

Here you can find the source of Deserialize(String filePath)

Description

Deserializes an object

License

Open Source License

Parameter

Parameter Description
filePath Path of the serialized object

Exception

Parameter Description
IOException an exception
ClassNotFoundException an exception

Declaration

public static Object Deserialize(String filePath) throws IOException, ClassNotFoundException 

Method Source Code


//package com.java2s;
import java.io.File;
import java.io.FileInputStream;

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

public class Main {
    /**/*from   w  ww  .j av a 2  s.  com*/
     * Deserializes an object
     * @param filePath Path of the serialized object
     * @return
     * @throws IOException
     * @throws ClassNotFoundException
     */
    public static Object Deserialize(String filePath) throws IOException, ClassNotFoundException {
        Object result = null;
        if (!new File(filePath).exists())
            return result;
        FileInputStream fileStream = new FileInputStream(filePath);
        ObjectInputStream objectStream = new ObjectInputStream(fileStream);
        result = objectStream.readObject();
        return result;
    }
}

Related

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