PushbackReader mark(int) method in Java with Examples
The mark() method of PushbackReader Class in Java is used to marks the current position of the PushbackReader. In the case of PushbackReader, this method always throws an exception as this method isn’t supported by the PushbackReader.
Syntax:
public void mark(int readAheadLimit)
Parameters: This method accepts a mandatory parameter readAheadLimit which is the limit on the number of characters that may be read while still preserving the mark. After reading this many characters, attempting to reset the stream may fail.
Return Value: This method do not returns any value.
Exception: This method throws IOException always as the mark() method is not supported.
Below methods illustrates the working of mark() method:
Program 1:
// Java program to demonstrate // PushbackReader mark(int) method import java.io.*; import java.util.*; class GFG { public static void main(String[] args) { try { // Initializing a StringReader and PushbackReader String s = "GeeksForGeeks"; StringReader stringReader = new StringReader(s); PushbackReader pushbackReader = new PushbackReader(stringReader); // mark the stream for // 5 characters using mark() pushbackReader.mark(5); // Close the stream using mark(int) pushbackReader.close(); System.out.println("Stream Closed."); } catch (Exception e) { System.out.println(e); } } } |
java.io.IOException: mark/reset not supported
Program 2:
// Java program to demonstrate // PushbackReader mark(int) method import java.io.*; import java.util.*; class GFG { public static void main(String[] args) { try { // Initializing a StringReader and PushbackReader String s = "GFG"; StringReader stringReader = new StringReader(s); PushbackReader pushbackReader = new PushbackReader(stringReader); // mark the stream for // 1 characters using mark() pushbackReader.mark(1); // Close the stream pushbackReader.close(); System.out.println("Stream Closed."); } catch (Exception e) { System.out.println(e); } } } |
java.io.IOException: mark/reset not supported
Reference: https://docs.oracle.com/javase/9/docs/api/java/io/PushbackReader.html#mark-int-
Recommended Posts:
- PushbackReader ready() method in Java with Examples
- PushbackReader reset() method in Java with Examples
- PushbackReader close() method in Java with Examples
- PushbackReader markSupported() method in Java with Examples
- PushbackReader read() method in Java with Examples
- PushbackReader read(char, int, int) method in Java with Examples
- PushbackReader skip(long) method in Java with Examples
- Java.io.PushbackReader Class in Java
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



