Java Object Deserialize from File deserializeFromFile(File file)

Here you can find the source of deserializeFromFile(File file)

Description

Utility method to deserialize an Object from given File.

License

Open Source License

Parameter

Parameter Description
file File source

Exception

Parameter Description
IOException an exception

Return

deserialized Object

Declaration

public static Object deserializeFromFile(File file) throws IOException 

Method Source Code


//package com.java2s;
/* IoUtils/*from   www .  j  av a 2s .  c  o  m*/
 * 
 * Created on Dec 8, 2004
 *
 * Copyright (C) 2004 Internet Archive.
 * 
 * This file is part of the Heritrix web crawler (crawler.archive.org).
 * 
 * Heritrix is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * any later version.
 * 
 * Heritrix is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser Public License
 * along with Heritrix; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.io.BufferedInputStream;

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

import java.io.IOException;

import java.io.ObjectInputStream;

public class Main {
    /**
     * Utility method to deserialize an Object from given File. 
     * 
     * @param file File source
     * @return deserialized Object
     * @throws IOException
     */
    public static Object deserializeFromFile(File file) throws IOException {
        ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)));
        Object object;
        try {
            object = ois.readObject();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            throw new RuntimeException(e);
        }
        ois.close();
        return object;
    }
}

Related

  1. deserialize(String path)
  2. deserialize(String path)
  3. deserialize(String path)
  4. deserializeFromDisk(String filePath)
  5. deserializeFromFile(File file)
  6. deserializeFromFile(String path)
  7. deserializeFromFile(String path)
  8. deserializeMap(File file)
  9. deserializeMyContext(String path)