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