Skip to content
Related Articles

Related Articles

Improve Article
BufferedInputStream markSupported() method in Java with Examples
  • Last Updated : 17 May, 2020

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()

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :