Java InputStream.read(byte[], int, int) method, how to block until the exact number of bytes has been read

前端 未结 4 518
悲&欢浪女
悲&欢浪女 2021-02-04 11:53

I\'m writing a simple client/server network application that sends and receives fixed size messages through a TCP socket.

So far, I\'ve been using the <

4条回答
  •  抹茶落季
    2021-02-04 12:05

    Use DataInputStream.readFully. Here is JavaDoc

    InputStream in = ...
    DataInputStream dis = new DataInputStream( in );
    byte[] array = ...
    
    dis.readFully( array );
    

提交回复
热议问题