📌  相关文章
📜  Java中的 Reader markSupported() 方法和示例

📅  最后修改于: 2022-05-13 01:54:24.479000             🧑  作者: Mango

Java中的 Reader markSupported() 方法和示例

Java中Reader类的markSupported()方法用来检查这个Reader是否支持mark()操作。它返回一个布尔值,说明阅读器是否支持标记。

句法:

public boolean markSupported()

参数:此方法不接受任何参数

返回值:此方法返回一个布尔值,用于说明此 Reader 是否支持 mark() 操作。如果是 markSupported,则返回 true。否则返回false。

以下方法说明了 markSupported() 方法的工作原理:

方案一:

// Java program to demonstrate
// Reader markSupported() method
  
import java.io.*;
import java.util.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        try {
  
            String str = "GeeksForGeeks";
  
            // Create a Reader instance
            Reader reader
                = new StringReader(str);
  
            // Check if the Reader is
            // markSupported using markSupported()
            System.out.println("Is Reader markSupported: "
                               + reader.markSupported());
  
            reader.close();
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
输出:
Is Reader markSupported: true

方案二:

// Java program to demonstrate
// Reader markSupported() method
  
import java.io.*;
import java.util.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        try {
            char[] str = { 'G', 'E', 'E', 'K', 'S' };
  
            // Create a Reader instance
            Reader reader
                = new CharArrayReader(str);
  
            // Check if the Reader is
            // markSupported using markSupported()
            System.out.println("Is Reader markSupported: "
                               + reader.markSupported());
  
            reader.close();
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
输出:
Is Reader markSupported: true

参考: https://docs.oracle.com/javase/9/docs/api/ Java/io/Reader.html#markSupported–