Thursday, October 9, 2025
HomeLanguagesJavaBufferedInputStream markSupported() method in Java with Examples

BufferedInputStream markSupported() method in Java with Examples

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

RELATED ARTICLES

Most Popular

Dominic
32342 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6712 POSTS0 COMMENTS
Nicole Veronica
11875 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11937 POSTS0 COMMENTS
Shaida Kate Naidoo
6833 POSTS0 COMMENTS
Ted Musemwa
7092 POSTS0 COMMENTS
Thapelo Manthata
6786 POSTS0 COMMENTS
Umr Jansen
6789 POSTS0 COMMENTS