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

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

Java中的 StringReader markSupported() 方法及示例

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

句法:

public boolean markSupported()

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

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

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

方案一:

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

方案二:

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

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