public class StringReader extends Reader
| Constructor and Description |
|---|
StringReader(String s)
创建一个新的字符串阅读器。
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
关闭流并释放与之相关联的任何系统资源。
|
void |
mark(int readAheadLimit)
标记流中的当前位置。
|
boolean |
markSupported()
告诉这个流是否支持mark()操作。
|
int |
read()
读一个字符
|
int |
read(char[] cbuf, int off, int len)
将字符读入数组的一部分。
|
boolean |
ready()
告诉这个流是否准备好被读取。
|
void |
reset()
将流重新设置为最近的标记,如果从未被标记,则将其重置到字符串的开头。
|
long |
skip(long ns)
跳过流中指定数量的字符。
|
public StringReader(String s)
s - 提供字符流的字符串。
public int read()
throws IOException
read在类别
Reader
IOException - 如果发生I / O错误
public int read(char[] cbuf,
int off,
int len)
throws IOException
read在类别
Reader
cbuf - 目的缓冲区
off - 开始编写字符的偏移量
len - 要读取的最大字符数
IOException - 如果发生I / O错误
public long skip(long ns)
throws IOException
ns参数可能为负,即使skip类中的skip方法在这种情况下抛出异常。 ns导致流向后跳。 负值返回值表示向后跳。 不可能从字符串的开头向后跳过。
如果整个字符串已被读取或跳过,则该方法不起作用,并始终返回0。
skip在
Reader
ns - 要跳过的字符数
IOException - 如果发生I / O错误
public boolean ready()
throws IOException
ready在类别
Reader
IOException - 如果流关闭
public boolean markSupported()
markSupported在类别
Reader
public void mark(int readAheadLimit)
throws IOException
mark在类别
Reader
readAheadLimit - 限制仍然保留标记时可能读取的字符数。
因为流的输入来自一个字符串,所以没有实际的限制,所以这个参数不能是负数,而是被忽略。
IllegalArgumentException - 如果
readAheadLimit < 0
IOException - 如果发生I / O错误
public void reset()
throws IOException
reset在类别
Reader
IOException - 如果发生I / O错误
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.