Most visited

Recently visited

Added in API level 1

StringReader

public class StringReader
extends Reader

java.lang.Object
    java.io.Reader
      java.io.StringReader


源代码是字符串的字符流。

摘要(Summary)

Inherited fields

From class java.io.Reader

Public constructors

StringReader(String s)

创建一个新的字符串阅读器。

公共方法(Public methods)

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)

跳过数据流中指定数量的字符。

继承方法(Inherited methods)

From class java.io.Reader
From class java.lang.Object
From interface java.lang.Readable
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Public constructors

StringReader

Added in API level 1
StringReader (String s)

创建一个新的字符串阅读器。

参数(Parameters)
s String: String providing the character stream.

公共方法(Public methods)

close

Added in API level 1
void close ()

关闭流并释放与其关联的所有系统资源。 一旦流被关闭,read(),ready(),mark()或reset()调用将会抛出一个IOException异常。 关闭以前关闭的流不起作用。

mark

Added in API level 1
void mark (int readAheadLimit)

标记流中的当前位置。 随后调用reset()会将流重新定位到这一点。

参数(Parameters)
readAheadLimit int: Limit on the number of characters that may be read while still preserving the mark. Because the stream's input comes from a string, there is no actual limit, so this argument must not be negative, but is otherwise ignored.
抛出异常(Throws)
IllegalArgumentException If readAheadLimit is < 0
IOException If an I/O error occurs

markSupported

Added in API level 1
boolean markSupported ()

告诉这个流是否支持mark()操作。

返回(Returns)
boolean true if and only if this stream supports the mark operation.

read

Added in API level 1
int read ()

读取一个字符。

返回(Returns)
int The character read, or -1 if the end of the stream has been reached
抛出异常(Throws)
IOException If an I/O error occurs

read

Added in API level 1
int read (char[] cbuf, 
                int off, 
                int len)

将字符读入数组的一部分。

参数(Parameters)
cbuf char: Destination buffer
off int: Offset at which to start writing characters
len int: Maximum number of characters to read
返回(Returns)
int The number of characters read, or -1 if the end of the stream has been reached
抛出异常(Throws)
IOException If an I/O error occurs

ready

Added in API level 1
boolean ready ()

告诉这个流是否准备好被读取。

返回(Returns)
boolean True if the next read() is guaranteed not to block for input
抛出异常(Throws)
IOException If the stream is closed

reset

Added in API level 1
void reset ()

将流重置为最近的标记,或者如果从未标记过,则将其重新设置为字符串的开头。

抛出异常(Throws)
IOException If an I/O error occurs

skip

Added in API level 1
long skip (long ns)

跳过数据流中指定数量的字符。 返回跳过的字符数。

即使Reader超类的skip方法在此情况下引发异常, ns参数也可能为负数。 ns会导致数据流向后跳转。 负的返回值表示向后跳转。 不可能跳过字符串的开头。

如果整个字符串已被读取或跳过,则此方法无效并始终返回0。

参数(Parameters)
ns long: The number of characters to skip
返回(Returns)
long The number of characters actually skipped
抛出异常(Throws)
IOException If an I/O error occurs

Hooray!