java.io.StreamCorruptedException:无效的流标题:00000001简单项目 [英] java.io.StreamCorruptedException: invalid stream header: 00000001 Simple Project

查看:204
本文介绍了java.io.StreamCorruptedException:无效的流标题:00000001简单项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,当我尝试反序列化信息时,我的项目(将项目序列化为文件夹然后反序列化的简单库存)抛出java.io.StreamCorruptedException:无效的流标题:00000001。我以前没有遇到过问题;但是,当我用Finder(mac)手动删除其中一个序列化文件时,这就是抛出Exception的时候。
我的反序列化代码是:

My problem is that my project (a simple Inventory in which Items are Serialized to a folder and then deserialized) is throwing a "java.io.StreamCorruptedException: invalid stream header: 00000001" when I try to deserialize the information. I did not have a problem before; however, when I manually deleted one of the serialized files with Finder(mac), this is when the Exception was thrown. My code for deserializing is:

private void compileInventory() {
    //run through text file and create inventory 

    Inv = new <Item>ArrayList();
    File f = new File(loc);
    File[] list = f.listFiles();
    Inv.clear();
    if (f.exists()) {
        for (File n : list) {

                try {
                    FileInputStream fileIn = new FileInputStream(n.getAbsolutePath());
                    ObjectInputStream in = new ObjectInputStream(fileIn);
                    Inv.add((Item) in.readObject());
                    in.close();
                    fileIn.close();
                } catch (IOException i) {
                    i.printStackTrace();
                    return;
                } catch (ClassNotFoundException c) {
                    System.out.println("Item class not found");
                    c.printStackTrace();
                    return;
                }
            }

    }
}


推荐答案

可能是你的mac在该文件夹中创建了一些系统文件,现在你的应用正在尝试去实现它们吗?

Could it be that your mac has created some system files in that folder, and now your app is trying to deserealize them?

这篇关于java.io.StreamCorruptedException:无效的流标题:00000001简单项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆