从文件读取到对象的arraylist,为什么我得到IOException?

时间:2017-05-06 15:46:35

标签: java arraylist file-read

我编写了一个将客户端的arraylist保存到文件的方法。在那之后,在我的程序开始时,我想从文件中读取并让所有客户端到arraylist。我的问题是程序抛出IOException以及这些注释:

Note: test.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

我的代码:

    ArrayList<Client>accountList=new ArrayList<Client>();
    File fileRead=new File("file.txt");

    try{
        FileInputStream arrayAccountsList=new FileInputStream(fileRead);
        ObjectInputStream ois=new ObjectInputStream(arrayAccountsList);
        accountList=(ArrayList<Client>)ois.readObject();
        arrayAccountsList.close();

    }
    catch(FileNotFoundException e){
        System.out.println("FileNotFoundException");
    }
    catch(IOException d){
        System.out.println("IOEXCEPTION");
    }
    catch(ClassNotFoundException f){
        System.out.println("ClassNotFoundException");
    }

你能告诉我这里做错了什么吗?非常感谢。

编辑:

stacktrace输出:

at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2624)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:3099)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:853)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:349)
at Bank.main(Bank.java:23)

23行是:

ObjectInputStream ois=new ObjectInputStream(arrayAccountsList);

0 个答案:

没有答案