InputStreamReader.markSupported 为 false
我需要从 InputStreamReader
中“取消读取”字符。为此,我想使用 mark
和 reset
但 markSupported
为 InputStreamReader
返回 false
code> 类,因为它不维护内部缓冲区和/或字符队列。
我知道 BufferedInputStream
和 PushbackInputStream
但这里都不合适,因为它们缓冲以字节为基础,而我需要字符。
Java 是否提供了可以不读取字符的缓冲字符读取器?实际上,让我进一步限制一下,我只需要取消读取一个字符(用于前瞻目的)。我真的需要保持自己的前瞻性吗?
I need to “un-read” characters from an InputStreamReader
. For that purpose I wanted to use mark
and reset
but markSupported
returns false
for the InputStreamReader
class, since it doesn’t maintain an internal buffer and/or queue of characters.
I know about BufferedInputStream
and PushbackInputStream
but neither is appropriate here since they buffer on byte basis, while I need characters.
Does Java offer a buffered character reader which can un-read characters? Actually, let me constrain that further, I only ever need to un-read a single character (for lookahead purposes). Do I really need to maintain my own lookahead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
两个基于字节流的类
java.io.BufferedInputStream
和java.io.PushbackInputStream
在同一个包中拥有基于字符流的对应类:The two byte-stream based classes
java.io.BufferedInputStream
andjava.io.PushbackInputStream
have their character-stream based counterparts in the same package:您尝试过 java.io.BufferedReader 吗?
Have you tried java.io.BufferedReader?
您可以使用 BufferedReader 包装输入流。
缓冲读取器确实支持标记和读取字符。
You could wrap the input stream using a
BufferedReader
The buffered reader does support mark and reads characters.