try
{
Employee test= null;
while(true)
{
test=(Employee)inputStream.readObject();
list.addANodeToStart(test);
}
}
catch(EOFException e)
{
System.out.println("Reached end of file.");
System.exit(0);嘿,伙计们,我有点问题。
在try块中,我有一段将员工添加到LinkedList中的代码。由于某些原因,当我放入while(true)块时,我的整个程序都无法工作,它只输出“到达文件末尾”。
然而,当我删除while(true)块时,它确实只添加了第一个Employee,因此使我的程序的其余部分可以工作,但不是全部。因为我需要添加多个员工的列表,让用户输入一个数字,并将该数字与员工编号进行比较,然后输出匹配的员工。
有什么想法吗?
发布于 2014-12-12 11:10:01
尝试以下操作:
try
{
Employee test= null;
while(true)
{
test=(Employee)inputStream.readObject();
list.addANodeToStart(test);
}
}
catch(EOFException e)
{
System.out.println("Reached end of file.");
}
// process the listhttps://stackoverflow.com/questions/27436188
复制相似问题