集册 Java实例教程 从文件反序列化对象

从文件反序列化对象

欢马劈雪     最近更新时间:2020-01-02 10:19:05

454
从文件反序列化对象


import java.awt.Color;

import java.awt.image.BufferedImage;
/*
来 自*
 N o w J a v a . c o m - 时  代  Java
*/

import java.io.*;

import java.util.ArrayList;

import java.util.logging.*;


public class Main{

    /**

     * Deserialize an object from file

     * @param filename The filename of the serialized object

     * @return The deserialized object

     */

    public static Object deserialize(String filename) {

        System.out.println("Deserializing " + filename);

        Object object = null;


        try {// 来 自 n o w j a   v  a . c o m - 时  代  Java

            FileInputStream fileIn = new FileInputStream(filename);

            ObjectInputStream in = new ObjectInputStream(fileIn);

            object = in.readObject();

            in.close();

            fileIn.close();

        } catch (IOException i) {

            Logger.getLogger(HelperFunctions.class.getName()).log(

                    Level.SEVERE, null, i);

        } catch (ClassNotFoundException c) {

            Logger.getLogger(
展开阅读全文