Android Object Serialization readObjectFromFile(File fileLocation)

Here you can find the source of readObjectFromFile(File fileLocation)

Description

read Object From File

Declaration

@SuppressWarnings("unchecked")
    public static <T> T readObjectFromFile(File fileLocation)
            throws IOException 

Method Source Code

//package com.java2s;

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

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;

import java.util.zip.GZIPInputStream;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T> T readObjectFromFile(File fileLocation)
            throws IOException {
        InputStream file = new FileInputStream(fileLocation);
        InputStream buffer = new GZIPInputStream(file);
        try (ObjectInput input = new ObjectInputStream(buffer)) {
            return (T) input.readObject();
        } catch (ClassNotFoundException e) {
            // Need to handle only one exception
            throw new IOException(e);
        }//from w ww. ja  v  a2s .  c  o m
    }
}

Related

  1. loadObjectFromFile(String filename)
  2. readObjectFromFile(String filename)
  3. saveObjectAsFile(String filename, Object object)
  4. writeObjectToFile(File fileLocation, Object obj)
  5. writeObjectToFile(Serializable obj, String filename)