Java CharArrayReader reset()方法
java.io.CharArrayReader.reset() 用于将流重置为最新标记。
1 语法
public void reset()
2 参数
无
3 返回值
无
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* java.io.CharArrayReader.reset()方法的例子
*/
import java.io.CharArrayReader;
import java.io.IOException;
public class Demo {
public static void main(String[] args) {
CharArrayReader car = null;
char[] ch = {'A', 'B', 'C', 'D', 'E'};
try {
// create new character array reader
car = new CharArrayReader(ch);
int value = 0;
// read till the end of the stream
while((value = car.read())!=-1) {
// convert integer to char
char c = (char)value;
// print characters
System.out.print(c + " ");
}
// reset invoked
car.reset();
System.out.println("\nReset() invoked");
// read till the end of the stream
while((value = car.read())!=-1) {
// convert integer to char
char c = (char)value;
// print characters
System.out.print(c + " ");
}
} catch(IOException e) {
// if I/O error occurs
e.printStackTrace();
} finally {
// releases any system resources associated with the stream
if(car!=null)
car.close();
}
}
}
输出结果为:
A B C D E
Reset() invoked
A B C D E
热门文章
优秀文章