Output an int i to a file
The Question is as follows: Explain the difference between the output of the following two fragments of code for outputting an int i to a file
i)
Code :
PrintWriter outfile = new PrintWriter(new FileWriter("ints.txt"));
outfile.print(i);
ii)
Code :
DataOutputStream out = new DataOutputStream(new FileOutputStream("ints.dat"));
out.writeInt(i);
I believe the PrintWriter coverts the stream into Unicode and the DataOutStream converts higher level data items to sequence of bytes.
What more can be said?
Re: Output an int i to a file
Quote:
the difference between the output
Have you tried executing the two segments?
What do they output? Can you copy and paste the output here to show us?
Use a hexeditor if needed.
Re: Output an int i to a file
For your section segment, you can talk about serialization, other than that do what norm said and run the code :)