Write a complete Java program that opens a binary file containing integers and displays the contents to the screen.
What will be an ideal response?
```
import java.io.ObjectInputStream;
import java.io.FileInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.FileNotFoundException;
public class BinaryInputDemo
{
public static void main(String args[])
{
try
{
ObjectInputStream inputStream =
new ObjectInputStream(new
FileInputStream("statistics.dat"));
int stat = 0;
try
{
while(true)
{
stat = inputStream.readInt();
System.out.println(stat);
}
}
catch(EOFException e)
{
System.out.println("End of file encountered");
}
inputStream.close();
}
catch(FileNotFoundException e)
{
System.out.println("Unable to locate file");
}
catch(IOException e)
{
System.out.println("Unable to read file");
}
}
}
```
You might also like to view...
Which of the following is the correct syntax to create a static route?
a. ip route
A technician is building a new network. Which of the following components would be the FIRST installed for the network?
A. MDF B. VPN C. EMI D. IDF