Java BufferedReader markSupported()方法与示例

BufferedReader类markSupported()方法

  • markSupported()方法在java.io包中可用。

  • markSupported()方法用于检查此BufferedReader是否支持mark()reset()方法。

  • markSupported()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • 在检查支持方法时,markSupported()方法不会引发异常。

语法:

    public boolean markSupported();

参数:

  • 它不接受任何参数。

返回值:

该方法的返回类型是布尔值,当此流支持它返回truemark()reset()方法,否则返回false。

示例

//Java程序演示示例 
//方法 
//BufferedReader-

import java.io.*;

public class MarkSupportedBR {
    public static void main(String[] args) throws Exception {
        //打开文本文件 
        //FileInputStream-
        FileInputStream fis = new FileInputStream("e:/includehelp.txt");

        //实例化InputStreamReader- 
        InputStreamReader inp_r = new InputStreamReader(fis);

        //实例化BufferedReader- 
        BufferedReader buff_r = new BufferedReader(inp_r);

        //检查是否此流
        //buff_r支持mark(),reset()
        //是否
        boolean status = buff_r.markSupported();
        System.out.println("buff_r.markSupported(): " + status);

        //检查是否此流
        //inp_r支持mark(),reset()
        //是否
        status = inp_r.markSupported();
        System.out.println("inp_r.markSupported(): " + status);

        fis.close();
        inp_r.close();
        buff_r.close();
    }
}

输出结果

buff_r.markSupported(): true
inp_r.markSupported(): false