-1

I want to read and write some values into the DataOutputStream, but sometimes the value is int -1.

I am able to write this value but while reading getting EOFException, I think the value -1 its reading a EOF.

Can someone help me to figure out how can I read and write -1 into DataOutputStream.

Thanks in advance.

AndroidDev
  • 888
  • 3
  • 13
  • 27
  • You are mistaken. Writing -1 does not cause an `EOFException` when reading. There is no problem here to solve. – user207421 Dec 09 '16 at 06:27

2 Answers2

3

To write an int value you can use dos.writeInt(x) and to read you can get int x = dis.readInt() There is no way to write a value which appears to be EOF and trigger an EOFException

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • So, can I write many -1 values and while reading EOF will occur only once reaching the end of stream. Is that you are trying to say? – AndroidDev Jul 01 '14 at 10:25
  • @LakshmiNaresh It is not only what he is 'trying' to say, it is what he *said*. These futile conversations about 'so you are saying' or 'what you're trying to say', or slightly rewording the answer and asking for confirmation for a slight rewordiong of the answer are just a waste time. – user207421 Dec 09 '16 at 06:28
0

to read it like int , you can:

 int valueInt = Integer.parseInt(readed_Value);
Borja Coalla
  • 216
  • 1
  • 3
  • 11