例子
以下示例显示了java.io.CharArrayReader.read(char [] b,int off,int len)方法的用法。
package com.jc2182;
import java.io.CharArrayReader;
import java.io.IOException;
public class CharArrayReaderDemo {
public static void main(String[] args) { CharArrayReader car = null;
char[] ch = {'H', 'E', 'L', 'L', 'O'};
char[] d = new char[5];
try {
// create new character array reader
car = new CharArrayReader(ch);
// read character to the destination buffer
car.read(d, 3, 2);
// for every character in the buffer
for (char c : d) {
int i = (int)c;
if(i == 0) {
System.out.println("0");
} else {
System.out.println(c);
}
}
} catch(IOException e) {
// if I/O error occurs
System.out.print("Stream is already closed");
} finally {
// releases any system resources associated with the stream
if(car!=null)
car.close();
}
}
}
让我们编译并运行以上程序,这将产生以下结果-