Reading Strings and Binary from the same FileInputStream

前端 未结 7 1973
离开以前
离开以前 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 23:01

    You need to use an InputStream. Readers are for character data. Look into wrapping your input stream with a DataInputStream, like:

    stream=new DataInputStream(new BufferedInputStream(new FileInputStream(...)));
    

    The data input stream will give you many useful methods to read various types of data, and of course, the base InputStream methods for reading bytes.

    (This is actually exactly what a HTTP server must do to read a request with content.)


    The readUTF doesn't read a line, it reads a string that was written in (modified) UTF8 format - refer to the JavaDoc.

提交回复
热议问题