Java FilterReader markSupported()方法与示例
FilterReader类markSupported()方法
markSupported()方法在java.io包中可用。
markSupported()方法用于检查是否此FilterReader流支持mark()方法。
markSupported()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
在检查支持方法时,markSupported()方法不会引发异常。
语法:
public boolean markSupported();
参数:
它不接受任何参数。
返回值:
该方法的返回类型为boolean,当此流支持方法时返回true,mark()否则返回false。
示例
//Java程序演示示例
//markSupported()FilterReader的布尔方法的说明
import java.io.*;
public class MarkSupportedOfFR {
public static void main(String[] args) throws Exception {
Reader r_stm = null;
FilterReader fr_stm = null;
try {
//实例化StringReader和
//FilterReader-
r_stm = new StringReader("JavaWorld!!!!");
fr_stm = new FilterReader(r_stm) {};
//通过使用markSupported()方法是
//检查流fr_stm是否支持
//mark()是否
boolean status = fr_stm.markSupported();
System.out.println("fr_stm.markSupported(): " + status);
} catch (Exception ex) {
System.out.println(ex.toString());
} finally {
//借助此块可以
//释放所有链接的必要资源
//与流
if (fr_stm != null) {
fr_stm.close();
}
}
}
}输出结果
fr_stm.markSupported(): true