Here is the question from JQPlus How many bytes will be written by the following code snippet in the file? ... DataOutputStream dos=new DataOutputStream( new FileOutputStream("data")); int x=0x12341234; dos.writeByte(x); dos.writeChar(x); dos.writeShort(x); dos.writeInt(x); dos.close(); the answer is 9. why? Thanks!
Roy Ben Ami
Joined: Jan 13, 2002
this one isnt as hard as u might think: dos.writeByte(x); //writes a byte dos.writeChar(x); // writes 2 bytes dos.writeShort(x); // writes 2 bytes dos.writeInt(x); // writes 4 bytes
alltogether 9. first you write a byte to the file. then you write a char and a short (each is 16 bit meaning 2 bytes). then an int ( 32 bits - 4 bytes).