用於讀取過濾字符流的抽象類。抽象類FilterReader本身提供了將所有請求傳遞到所包含流的默認方法。 FilterReader 的子類應該重寫其中一些方法,並且還可以提供其他方法和字段。
構造函數:
- protected FilterReader(讀入):創建一個新的過濾閱讀器。
方法:
- 無效close():關閉流並釋放與其關聯的所有係統資源。關閉流後,進一步的 read()、ready()、mark()、reset() 或 skip() 調用將引發 IOException。關閉之前關閉的流沒有任何效果。
Syntax :public void close() throws IOException Throws: IOException
- 無效標記(int readAheadLimit):標記流中的當前位置。
Syntax :public void mark(int readAheadLimit) throws IOException 參數: readAheadLimit - 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
- 布爾值markSupported():告知此流是否支持mark()操作。
Syntax :public boolean markSupported() 返回: true if and only if this stream supports the mark operation.
- int read():讀取單個字符。
Syntax :public int read() throws IOException Returns: The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached Throws: IOException
- int 讀取(char[] cbuf,int 關閉,int len):將字符讀入數組的一部分。
Syntax :public int read(char[] cbuf, int off, int len) throws IOException 參數: cbuf - Destination buffer off - Offset at which to start storing characters len - Maximum number of characters to read 返回: The number of characters read, or -1 if the end of the stream has been reached Throws: IOException
- 布爾值ready():告知該流是否已準備好讀取。
Syntax :public boolean ready() throws IOException 返回: 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
- 無效reset():重置流。
Syntax :public void reset() throws IOException Throws: IOException
- 長跳過(長n):跳過字符。
Syntax :public long skip(long n) throws IOException 參數: n - The number of characters to skip 返回: The number of characters actually skipped Throws: IOException
程序:
//Java program illustrating FilterReader class methods
import java.io.*;
class FilterReaderdemo
{
public static void main(String[] args) throws IOException
{
Reader r = new StringReader("GeeksforGeeks");
FilterReader fr = new FilterReader(r)
{
};
char ch[] = new char[8];
//illustrating markSupported()
if(fr.markSupported())
{
//illustrating mark() method
System.out.println("mark method is supported");
fr.mark(100);
}
//illustrating skip() method
fr.skip(5);
//illustrating ready()
if(fr.ready())
{
//illustrating read(char[] cbuff,int off,int len)
fr.read(ch);
for (int i = 0; i < 8; i++)
{
System.out.print(ch[i]);
}
//illustrating reset()
fr.reset();
for (int i = 0; i <5 ; i++)
{
//illustrating read()
System.out.print((char)fr.read());
}
}
//closing the stream
fr.close();
}
}
輸出:
mark method is supported forGeeksGeeks
相關用法
- Java Java.io.FilterReader.close()用法及代碼示例
- Java Java.io.FilterReader.mark()用法及代碼示例
- Java Java.io.FilterReader.markSupported()用法及代碼示例
- Java Java.io.FilterReader.read()用法及代碼示例
- Java Java.io.FilterReader.ready()用法及代碼示例
- Java Java.io.FilterReader.reset()用法及代碼示例
- Java Java.io.FilterReader.skip()用法及代碼示例
- Java Java.io.FilterInputStream.available()用法及代碼示例
- Java Java.io.FilterInputStream.mark()用法及代碼示例
- Java Java.io.FilterInputStream.markSupported()用法及代碼示例
- Java Java.io.FilterInputStream.read()用法及代碼示例
- Java Java.io.FilterInputStream.reset()用法及代碼示例
- Java Java.io.FilterInputStream.skip()用法及代碼示例
- Java Java.io.FilterOutputStream.Close()用法及代碼示例
- Java Java.io.FilterOutputStream.flush()用法及代碼示例
- Java Java.io.FilterOutputStream.write()用法及代碼示例
- Java Java.io.FilterWriter.close()用法及代碼示例
- Java Java.io.FilterWriter.flush()用法及代碼示例
- Java Java.io.FilterWriter.write()用法及代碼示例
- Java Java.io.FilterWriter.available()用法及代碼示例
- Java Java.io.FilterWriter用法及代碼示例
- Java Java.io.FilterInputStream用法及代碼示例
- Java Java.io.FilterOutputStream用法及代碼示例
- Java Java.io.File.canExecute()用法及代碼示例
- Java Java.io.File.canRead()用法及代碼示例
注:本文由純淨天空篩選整理自佚名大神的英文原創作品 Java.io.FilterReader class in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。