FilterReader.read()方法示例
FilterReader.read()
具有以下语法。
public int read() throws IOException
示例
在下面的代码中展示了如何使用FilterReader.read()
方法。
import java.io.FilterReader; import java.io.Reader; import java.io.StringReader; public class Main {// from w wW.yI I B A I .CO m public static void main(String[] args) throws Exception { int i = 0; char c; // create new reader Reader r = new StringReader("ABCDEF"); // create new filter reader FilterReader fr = new FilterReader(r) { }; // read till the end of the stream while ((i = fr.read()) != -1) { // converts integer to character c = (char) i; // print System.out.println("Character read: " + c); } } }
上面的代码生成以下结果。
Character read: A Character read: B Character read: C Character read: D Character read: E Character read: F