集册 Java实例教程 取消序列化列表

取消序列化列表

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

443
取消序列化列表


//package com.nowjava;
/*
 from 时 代 J a v a 
*/

import java.io.*;

import java.util.ArrayList;

import java.util.List;


public class Main {

    public static <T> List<T> unserializList(String path) {

        File file = new File(path);

        List<T> collections = new ArrayList<T>();

        ObjectInputStream objectInputStream = null;

        try {

            InputStream inputStream = new FileInputStream(file);

            objectInputStream = new ObjectInputStream(inputStream);

            while (true) {

                try {

                    T t = (T) objectInputStream.readObject();

                    collections.add(t);

                } catch (EOFException e) {

                    break;/*from 时   代    Java - nowjava.com*/

                }

            }

        } catch (Exception e) {

            e.printStackTrace();

        } finally {

            
展开阅读全文