Help: Streams of primitive elements


Help is available for each task, or you can go straight to the solution source code.

Task 1

Open a DataOutputStream to file junk. Write out the following elements:
		int: 34
		String: "hello"
		double: 3.14159
		byte: 2

You must open a FileOutputStream on file junk and then attach the DataOutputStream. Use methods writeInt and so on to write the data.

Task 2

Close the file and read the values back in. Use DataInputStream.
Closing the DataOutputStream will close all streams down the line as well. Use methods such as readInt.

Task 3

Verify that the values read in are the same that were written. Print "ok" or "not ok" for each consistency check.
To verify values, do simple tests like:
if ( i==34 ) System.out.println("readInt ok");

Copyright © 1996-1997 MageLang Institute. All Rights Reserved.