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”.
import java.io.*;
public class GFG {
public static void main(String[] args)
{
FileInputStream inputStream
= new FileInputStream(
"c:/demo.txt" );
BufferedInputStream buffInputStr
= new BufferedInputStream(
inputStream);
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”.
import java.io.*;
public class GFG {
public static void main(String[] args)
{
FileInputStream inputStream
= new FileInputStream( "c:/demo.txt" );
BufferedInputStream buffInputStr
= new BufferedInputStream(inputStream);
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
Share your thoughts in the comments
Please Login to comment...