当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java StringReader markSupported()用法及代码示例


Java中StringReader类的markSupported()方法用于检查此StringReader是否支持mark()操作。它返回一个布尔值,该状态指示是否标记了阅读器。

用法:

public boolean markSupported()

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


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

下面的方法说明了markSupported()方法的用法方式:

示例1:

// 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

示例2:

// 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–



相关用法


注:本文由纯净天空筛选整理自Code_r大神的英文原创作品 StringReader markSupported() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。