【问题标题】:Java Serialization empty file [closed]Java序列化空文件[关闭]
【发布时间】:2012-10-13 13:15:15
【问题描述】:

我有一些 java 序列化代码。它编译并正常运行。但生成的文件是空的。下面是我的代码

参数可以是整数数组列表、字符串数组列表或整数数组列表数组列表

Model model = new Model(
    pennTreeTags,
    tagsCount,
    iOccurTable,
    fOccurTable,
    alVocab,
    aiVocabCount,
    wordTagTable,
    fWordTagProb
);

try 
{
    FileInputStream fileIn = new FileInputStream(argv[2]);
    ObjectInputStream in = new ObjectInputStream(fileIn);
    model = (Model) in.readObject();
    in.close();
    fileIn.close();
}
catch (EOFException ex) 
{ 
    //This exception will be caught when EOF is reached
    System.out.println("End of file reached.");
}
catch(IOException i)
{
    i.printStackTrace();
    return;
}
catch(ClassNotFoundException c)
{
    System.out.println("Model class not found");
    c.printStackTrace();
    return;
}

【问题讨论】:

  • 你发错代码了吗?这里没有发生序列化 - 这看起来像是从文件中反序列化?
  • 当您编写此代码时,您是否只是决定将自己锁在一个无法访问 Internet 且没有可供参考的 Java 文档或书籍的房间中?

标签: java serialization arraylist


【解决方案1】:

您没有向任何文件写入任何内容。您只是从文件中读取。 如果要写入文件,请使用 *Output*Stream。

【讨论】:

  • 哈哈是的,我刚刚意识到....难怪我的文件是空的,谢谢!
猜你喜欢
  • 2014-07-18
  • 2013-10-22
  • 1970-01-01
  • 2012-12-27
  • 1970-01-01
  • 1970-01-01
  • 2012-09-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多