Reading Strings and Binary from the same FileInputStream

前端 未结 7 1977
离开以前
离开以前 2021-01-17 22:29

I have a file that contains some amount of plain text at the start followed by binary content at the end. The size of the binary content is determined by some one of the pla

7条回答
  •  爱一瞬间的悲伤
    2021-01-17 22:52

    You could use RandomAccessFile. Use readLine() to read the plain text at the start (note the limitations of this, as described in the API), and then readByte() or readFully() to read the subsequent binary data.

    Using the underlying FileInputStream to read returns empty byte arrays.

    That's because you have wrapped the stream in a BufferedReader, which has probably consumed all the bytes from the stream when filling up its buffer.

提交回复
热议问题