Most visited

Recently visited

Added in API level 1

PushbackReader

public class PushbackReader
extends FilterReader

java.lang.Object
   ↳ java.io.Reader
     ↳ java.io.FilterReader
       ↳ java.io.PushbackReader


字符流阅读器,允许将字符推回到流中。

Summary

Inherited fields

From class java.io.FilterReader
From class java.io.Reader

Public constructors

PushbackReader(Reader in, int size)

使用给定大小的推送缓冲区创建新的推回阅读器。

PushbackReader(Reader in)

使用单字符后推缓冲区创建新的推回式阅读器。

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 n)

跳过字符。

void unread(char[] cbuf, int off, int len)

通过将字符数组的一部分复制到推回缓冲区的前面来推回部分字符。

void unread(char[] cbuf)

通过将字符数组复制到推回缓冲区的前面来推回字符数组。

void unread(int c)

通过将单个字符复制到推回缓冲区的前面来推回单个字符。

Inherited methods

From class java.io.FilterReader
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

PushbackReader

Added in API level 1
PushbackReader (Reader in, 
                int size)

使用给定大小的推送缓冲区创建新的推回阅读器。

Parameters
in Reader: The reader from which characters will be read
size int: The size of the pushback buffer
Throws
IllegalArgumentException if size is <= 0

PushbackReader

Added in API level 1
PushbackReader (Reader in)

使用单字符后推缓冲区创建新的推回式阅读器。

Parameters
in Reader: The reader from which characters will be read

Public methods

close

Added in API level 1
void close ()

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

Throws
IOException If an I/O error occurs

mark

Added in API level 1
void mark (int readAheadLimit)

标记流中的当前位置。 markPushbackReader总是抛出异常。

Parameters
readAheadLimit int: Limit on the number of characters that may be read while still preserving the mark. After reading this many characters, attempting to reset the stream may fail.
Throws
IOException Always, since mark is not supported

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, false otherwise. Note that returning false does not guarantee that the next read will block.
Throws
IOException If an I/O error occurs

reset

Added in API level 1
void reset ()

重置流。 reset的方法PushbackReader总是抛出异常。

Throws
IOException Always, since reset is not supported

skip

Added in API level 1
long skip (long n)

跳过字符。 此方法将阻塞,直到某些字符可用,发生I / O错误或到达流的末尾。

Parameters
n long: The number of characters to skip
Returns
long The number of characters actually skipped
Throws
IllegalArgumentException If n is negative.
IOException If an I/O error occurs

unread

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

通过将字符数组的一部分复制到推回缓冲区的前面来推回部分字符。 在此方法返回后,要读取的下一个字符将具有值cbuf[off] ,之后的字符将具有值cbuf[off+1] ,等等。

Parameters
cbuf char: Character array
off int: Offset of first character to push back
len int: Number of characters to push back
Throws
IOException If there is insufficient room in the pushback buffer, or if some other I/O error occurs

unread

Added in API level 1
void unread (char[] cbuf)

通过将字符数组复制到推回缓冲区的前面来推回字符数组。 在此方法返回后,要读取的下一个字符将具有值cbuf[0] ,之后的字符将具有值cbuf[1] ,等等。

Parameters
cbuf char: Character array to push back
Throws
IOException If there is insufficient room in the pushback buffer, or if some other I/O error occurs

unread

Added in API level 1
void unread (int c)

通过将单个字符复制到推回缓冲区的前面来推回单个字符。 此方法返回后,要读取的下一个字符将具有值(char)c

Parameters
c int: The int value representing a character to be pushed back
Throws
IOException If the pushback buffer is full, or if some other I/O error occurs

Hooray!