Java.io.Reader.markSupported() 方法

  • 描述

    java.io.Reader.markSupported() 方法告诉此流是否支持mark()操作。
  • 声明

    以下是java.io.Reader.markSupported()方法的声明。
     public boolean markSupported()
  • 参数

    N/A
  • 返回值

    当且仅当此流支持标记操作时,此方法才返回 true。
  • 异常

    IOException - 如果流不支持 mark(),或者发生其他一些 I/O 错误。
  • 例子

    以下示例显示java.io.Reader.read()方法的用法。
     
    package com.jc2182;
    
    import java.io.*;
    
    public class ReaderDemo {
       public static void main(String[] args) {
          String s = "Hello World";
    
          // create a new StringReader
          Reader reader = new StringReader(s);
    
          try {
             // read the first five chars
             for (int i = 0; i < 5; i++) {
                char c = (char) reader.read();
                System.out.print("" + c);
             }
    
             // change line
             System.out.println();
    
             // check if mark is supported
             System.out.println("" + reader.markSupported());
    
             // close the stream
             reader.close();
    
          } catch (IOException ex) {
             ex.printStackTrace();
          }
       }
    }
    
    让我们编译并运行以上程序,这将产生以下结果-
     
    Hello
    true