Open In App
Related Articles

BufferedInputStream markSupported() method in Java with Examples

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
The markSupported() method of BufferedInputStream class in Java is used to verify whether the input stream supports the mark and reset method or not. If any of the two methods is not supported by the input stream then the program will return false else true. Syntax:
public boolean markSupported()
Parameters: This method does not accept any parameter. Return value: This method returns a boolean indicating the supportability the mark and reset methods. Overrides: The method is overridden by the markSupported in FilterInputStream class. Exception: This method does not throw any exception. Below programs illustrate markSupported() method in BufferedInputStream class in IO package: Program 1: Assume the existence of file “c:/demo.txt”.
// Java program to illustrate
// BufferedInputStream markSupported() method
  
import java.io.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Create input stream 'demo.txt'
        // for reading containing text "GEEKS"
        FileInputStream inputStream
            = new FileInputStream(
                "c:/demo.txt");
  
        // Convert inputStream to
        // bufferedInputStream
        BufferedInputStream buffInputStr
            = new BufferedInputStream(
                inputStream);
  
        // Returns true if mark()
        // and reset () supports
        boolean bool
            = buffInputStr
                  .markSupported();
  
        System.out.println(
"Support for mark()"
+" and reset(): "
 + bool);
    }
}

                    
Output:
Support for mark() and reset() : true
Program 2: Assume the existence of file “c:/demo.txt”.
// Java program to illustrate
// BufferedInputStream.markSupported() method
  
import java.io.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Create input stream 'demo.txt'
        // for reading containing text "MRNOTSUPP"
        FileInputStream inputStream
            = new FileInputStream("c:/demo.txt");
  
        // Convert inputStream to
        // bufferedInputStream
        BufferedInputStream buffInputStr
            = new BufferedInputStream(inputStream);
  
        // Returns false if mark()
// and reset () not supported
        boolean bool
 = buffInputStr.markSupported();
  
        System.out.println(
"Support for mark()"
+" and reset(): "
 + bool);
    }
}

                    
Output:
Support for mark() and reset() : false
References: https://docs.oracle.com/javase/10/docs/api/java/io/BufferedInputStream.html#markSupported()

Last Updated : 17 May, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads