public class BinaryInputDemo
1:
2: import java.io.*;
3:
4: public class BinaryInputDemo
5: {
6: public static void main(String[] args)
7: {
8: try
9: {
10: ObjectInputStream inputStream =
11: new ObjectInputStream(new FileInputStream("numbers.dat"));
12: int n;
13: System.out.println("Reading the nonnegative integers");
14: System.out.println("in the file numbers.dat.");
15: n = inputStream.readInt( );
16: while (n >= 0)
17: {
18: System.out.println(n);
19: n = inputStream.readInt( );
20: }
21:
22: System.out.println("End of reading from file.");
23: inputStream.close( );
24: }
25: catch(FileNotFoundException e)
26: {
27: System.out.println("Cannot find file numbers.dat.");
28: }
29: catch(IOException e)
30: {
31: System.out.println("Problem with input from file numbers.dat.");
32: }
33: }
34: }