Signup/Sign In
PUBLISHED ON: MARCH 1, 2021

BufferedReader markSupported() Method in Java

In this tutorial, we will learn about the markSupported() method of BufferedReader class in Java. The markSupported() method of BufferedReader class in Java is used to verify whether the stream supports the mark() method or not. It returns the boolean value true if the stream supports mark() otherwise it returns false.

Syntax

This is the syntax declaration of the markSupported() method, this method does not accept any parameter. This method returns a boolean value indicating the supportability of the mark() method by the stream.

public boolean markSupported()

Example 1

In this example, we are checking whether the given stream supports the mark() method or not, in this case, markSupported() method is returning the true value it means the stream supports the mark() method

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
class StudyTonight
{
	public static void main(String[] args) throws IOException 
	{ 
		try 
		{
			FileReader	fileReader = new FileReader("E://studytonight//output.txt"); 
			BufferedReader br = new BufferedReader(fileReader);
			System.out.println(br.markSupported());  
			fileReader.close();
			br.close();
		}
		catch(Exception e)
		{
			System.out.println("Error: "+e.toString());
		}
	} 
}


true

Example 2

In this example, we are checking whether the given stream supports the mark() method or not, in this case, markSupported() method is returning the false value it means the stream does not support the mark() method

import java.io.BufferedReader;
import java.io.FileReader;
class StudyTonight
{
	public static void main(String[] args)  
	{ 
		try 
		{
			FileReader	fileReader = new FileReader("E://abc.txt"); 
			BufferedReader br = new BufferedReader(fileReader);
			System.out.println(br.markSupported());  
			fileReader.close();
			br.close();
		}
		catch(Exception e)
		{
			System.out.println("Error: "+e.toString());
		}
	} 
}


false

Conclusion:

In this tutorial, we learned about markSupported() method of BufferedReader class in Java. The markSupported() method of BufferedReader class in Java is used to verify whether the stream supports the mark() method or not. It returns the boolean value true if the stream supports mark() otherwise it returns false.



About the author:
I am the founder of Studytonight. I like writing content about C/C++, DBMS, Java, Docker, general How-tos, Linux, PHP, Java, Go lang, Cloud, and Web development. I have 10 years of diverse experience in software development.