Java BufferedReader skip()方法
java.io.BufferedReader.skip(long n) 用于跳过字符。
1 语法
public long skip(long n)
2 参数
n:要跳过的字符数。
3 返回值
返回跳过的实际字符数。
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* java.io.BufferedReader.skip(long n)方法的例子
*/
import java.io.BufferedReader;
import java.io.StringReader;
public class Demo {
public static void main(String[] args) throws Exception {
String s ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
StringReader sr = null;
BufferedReader br = null;
try {
// create and assign a new string reader
sr = new StringReader(s);
// create new buffered reader
br = new BufferedReader(sr);
// reads and prints BufferedReader
int value = 0;
while((value = br.read()) != -1) {
// skips a character
br.skip(1);
System.out.print((char)value);
}
} catch (Exception e) {
// exception occurred.
e.printStackTrace();
} finally {
// releases any system resources associated with the stream
if(sr!=null)
sr.close();
if(br!=null)
br.close();
}
}
}
输出结果为:
ACEGIKMOQSUWY
热门文章
优秀文章