datainput stream

From: Amey Samant (ameyas7_at_yahoo.com)
Date: 12/09/03


Date: 8 Dec 2003 21:05:32 -0800

hi all

i was trying to read an integer from keyboard with DataInputStream
can someone explain the behaviour of the following code ????

<code>
DataInputStream dis=new DataInputStream(System.in);
DataOutputStream dout = new DataOutputStream(System.out);
a=dis.readInt();
System.out.println("Using system.out a = "+a);
dout.writeInt(a);
a++;
System.out.println("Using system.out a = "+a);
dout.writeInt(a);
dout.flush();
</code>

the output is as under when 56 was entered as input
<output>
Using system.out a = 892734730
56
Using system.out a = 892734731
56

</output>

isnt it logical that if readInt reads an integer (56) , variable a
should store 56 & not some other value ....
what format does the DataInput reads in ?
coz when DataOutput is used the 56 appears corectly also the character
' ' where did it come from :O ?

how do you store value in an int variable using DataInputStream or is
it not meant for that ;) ?
i understand that stream stores it in different format that System.out
does not understand
but if we use the variable 'a' in some computation (of course we will
otherwise why will you want to read it ;) )then the whole computation
will go wrong
what am i missing ?

amey