Java BufferedInputStream markSupported()方法

java.io.BufferedInputStream.markSupported() 测试输入流是否支持mark和reset方法。

1 语法

public boolean markSupported()

2 参数

3 返回值

如果流类型支持mark()和read()方法,该方法返回true,否则该方法返回false。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.io.BufferedInputStream.markSupported()方法的例子
 */
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;

public class Demo {
    public static void main(String[] args) throws Exception {
        InputStream inStream = null;
        BufferedInputStream bis = null;
        boolean bool = false;

        try {
            // open input stream test.txt for reading purpose.
            inStream = new FileInputStream("d:/test.txt");

            // input stream is converted to buffered input stream
            bis = new BufferedInputStream(inStream);

            // returns true if mark() and read() supports
            bool = bis.markSupported();
            System.out.println("Support for mark() and reset() : "+bool);

        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            // releases any system resources associated with the stream
            if(bis!=null)
                bis.close();
            if(inStream!=null)
                inStream.close();
        }
    }
}

假设test.txt内容如下:

ABCDE

输出结果为:

Support for mark() and reset() : true

热门文章

优秀文章