Я получаю эту ошибку:
bill value:$ 0.10
bill value: $0.05
bill value: $0.01
bill value: $100.00
Exception in thread "main" java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at ReadMoney.main(ReadMoney.java:12)
================== Мой код:
//import java.util.Date;
public class ReadMoney
{
public static void main(String argv[]) throws Exception
{
FileInputStream fis = new FileInputStream("money.out");
ObjectInputStream ois = new ObjectInputStream(fis);
Object read;
try
{
while ((read = ois.readObject()) != null)
{
if (read instanceof Bill)
{
System.out.println("bill value: " + read);
}
else if (read instanceof Quarter)
{
}// while
else if (read instanceof Dime)
{
System.out.println("bill value:" + read);
}
else if (read instanceof Nickel)
{
System.out.println("bill value:" + read);
}
else if (read instanceof Penny)
{
System.out.println("bill value:" + read);
}
else if (read instanceof Bill)
{
System.out.println("bill value:" + read );
}
Money quarter = (Money) ois.readObject();
System.out.println("Quarter: "+ quarter);
System.out.println("Quarter: "+ quarter);
Money dime = (Money) ois.readObject();
System.out.println("Dime:" + dime);
Money nickel = (Money)ois.readObject();
System.out.println("Nickel:" + nickel);
Money penny = (Money) ois.readObject();
System.out.println("Penny:" + penny);
Money bill = (Money) ois.readObject();
System.out.println("Bill: " + bill);
}// try
} catch (IllegalBillException ibe)
{
System.out.println("End of file reached");
}
ois.close();
fis.close();
}// main
}// class
I 'Я почти уверен, что мой блок try и catch правильный, но моя программа не печатает значение в 2 квартала, а также текст с надписью «достигнут конец файла» по какой-то странной причине.= /