Java BufferedReader,用于零终止的字符串 [英] Java BufferedReader for zero-terminated strings
问题描述
我需要从Java中的InputStream中读取零终止的字符串。
I need to read zero-terminated strings from InputStream in Java.
是否存在类似于BufferedReader.readLine()方法的零终止字符串读取?
Is there similar to BufferedReader.readLine() method for reading zero-terminated strings?
推荐答案
否。 Java不能这样识别以零结尾的字符串。您必须阅读 InputStream
并查找一个0字节。
No. Java doesn't recognise a zero-terminated string as such. You'll have to read the InputStream
and look for a 0 byte.
请注意,这不能解决字符编码的问题。 InputStream
将为您提供字节流,然后您必须通过 Reader
将其编码为字符。如果您使用多字节字符编码,则问题会变得更加复杂。
Note that this doesn't address the issue of character-encoding. The InputStream
will give you the stream of bytes, and you'll then have to encode to characters via a Reader
. If you have a multi-byte character encoding then the issue becomes more complex.
这篇关于Java BufferedReader,用于零终止的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!