【问题标题】:Can I set the file index to the start of the file?我可以将文件索引设置为文件的开头吗?
【发布时间】:2013-04-15 07:15:09
【问题描述】:

我希望能够在将一个对象流式传输到文件后从文件中读取该对象。 现在,当我第一次阅读时它工作正常,但是当我尝试再次阅读(另一个对象)时,出现了一个我无法处理的异常。

现在,我猜文件索引到了文件的末尾,因此我无法再次从中读取。

我错了吗?如果不是,我可以将文件索引设置为文件的开头吗?

try{
    Classba cb=new Classba();
    FileOutputStream fos=new FileOutputStream(args[0]);
    ObjectOutputStream oos=new ObjectOutputStream(fos);
    oos.writeObject(cb);
    FileInputStream fis=new FileInputStream(args[0]);
    ObjectInputStream ois=new ObjectInputStream(fis);
    Classba cb2;
    cb2=(Classba)ois.readObject();
    cb2.print();   
    Classba cb3;          //*OK Till Here*//
    cb3=(Classba)ois.readObject();
}

【问题讨论】:

标签: java fileinputstream fileoutputstream


【解决方案1】:

您可以在您的ObjectInputStream 上调用reset() 方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多