简体   繁体   English

如何在DataOutputStream中读取和写入整数-1

[英]How to read and write integer -1 into DataOutputStream

I want to read and write some values into the DataOutputStream, but sometimes the value is int -1. 我想读写一些值到DataOutputStream中,但有时值是int -1。

I am able to write this value but while reading getting EOFException, I think the value -1 its reading a EOF. 我能够编写此值,但是在读取EOFException时,我认为值-1表示读取EOF。

Can someone help me to figure out how can I read and write -1 into DataOutputStream. 有人可以帮我弄清楚如何读写-1到DataOutputStream中。

Thanks in advance. 提前致谢。

要编写一个int值,您可以使用dos.writeInt(x)来读取,您可以得到int x = dis.readInt()无法写入一个看似EOF的值并触发EOFException

像int一样阅读,您可以:

 int valueInt = Integer.parseInt(readed_Value);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM