Android Object Serialization getObjectFormFile(String filePath)

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

Description

get Object Form File

Declaration

public static Object getObjectFormFile(String filePath) 

Method Source Code

//package com.java2s;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

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

import java.io.StreamCorruptedException;

public class Main {
    public static Object getObjectFormFile(String filePath) {
        if (filePath == null || filePath.length() == 0)
            return null;
        try {/* ww  w  .  j ava 2 s.c om*/
            File file = new File(filePath);
            if (file.exists()) {
                ObjectInputStream ois = new ObjectInputStream(
                        new FileInputStream(file));
                Object object = ois.readObject();
                return object;
            }
        } catch (StreamCorruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. writeQueueToFile(Queue list, String filePath)
  2. ObjectToByte(Serializable obj)
  3. obj2Bytes(Object obj)
  4. obj2Bytes(Object obj)
  5. objectToByte(Object obj)