How to use DataInputStream and DataOutputStream?
DataInputStream give us the power to write and read primitive data type to a media such as file. Both of this class have the corresponding method to write primitive data and read it back.
Using this class make it easier to read integer, float, double data and others without needing to interpret if the read data should be an integer or a float data. Let's see our code below.
The generated result of our program are:
City Id: 1
City Name: Green Lake City
City Population: 500000
City Temperature: 15.5