Java序列化空文件
我有一些java序列化代码。它可以正确编译和运行。但是结果文件是空的。下面是我的代码 参数可以是整数的arraylist、字符串的arraylist或整数的arraylistJava序列化空文件,java,serialization,arraylist,Java,Serialization,Arraylist,我有一些java序列化代码。它可以正确编译和运行。但是结果文件是空的。下面是我的代码 参数可以是整数的arraylist、字符串的arraylist或整数的arraylist Model model = new Model( pennTreeTags, tagsCount, iOccurTable, fOccurTable, alVocab, aiVocabCount, wordTagTable, fWordTagProb );
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;
}
你没有向任何文件写入任何内容。您仅从文件中读取。
如果要写入文件,请使用*Output*流。是否发布了错误的代码?这里没有发生序列化-这看起来像是从文件中反序列化?您是否决定在编写此代码时将自己锁在一个没有互联网接入、没有java文档或书籍可供参考的房间?哈哈,是的,我刚刚意识到……难怪我的文件是空的,谢谢!