VOOZH about

URL: https://www.geeksforgeeks.org/java/bytebuffer-mark-methods-in-java-with-examples/

⇱ ByteBuffer mark() methods in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ByteBuffer mark() methods in Java with Examples

Last Updated : 27 Jun, 2019
The mark() method of java.nio.ByteBuffer Class is used to set this buffer's mark at its position. Syntax:
public ByteBuffer mark()
Return Value: This method returns this buffer. Below are the examples to illustrate the mark() method: Examples 1:
Output:
position before reset: 4
position after reset: 2
Examples 2: To demonstrate InvalidMarkException
Output:
position before reset: 1

new position is less than the position we marked before 
Exception throws: java.nio.InvalidMarkException
Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/ByteBuffer.html#mark--
Comment