Java Object Deserialize from File deserialize(String fileName)

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

Description

deserialize

License

Apache License

Declaration

public static Object deserialize(String fileName) 

Method Source Code


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

import java.io.*;

public class Main {

    public static Object deserialize(String fileName) {
        ObjectInputStream ois = null;
        try {/*from  w w w .j  a  v  a2 s  . co m*/
            FileInputStream in = new FileInputStream(fileName);
            ois = new ObjectInputStream(in);
            return ois.readObject();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            if (ois != null) {
                try {
                    ois.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static Object deserialize(byte[] b) {
        ObjectInputStream ois = null;
        try {
            ByteArrayInputStream in = new ByteArrayInputStream(b);
            ois = new ObjectInputStream(in);
            return ois.readObject();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            if (ois != null) {
                try {
                    ois.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

Related

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