In the buffer class, there are two such methods: Flip and rewind. Check out their API documentation to see the following instructions:
Flip
Public final Buffer Flip ()
Flips this buffer. The limit is set to the current position and then the position are set to zero. If The mark is defined then it's discarded. Rewnd:
Public Final Buffer Rewind () Rewinds this buffer. The position is set to zero and the mark is discarded. Description: What is the difference between these three methods for the buffer class? Why do you have these three methods? Let's start with the first question, simply flip: set limit to the current position, set position as the starting position, that is, the 0;clear method, set the position to 0, set limit to buffer capacity, This is the buffer capacity. The rewind method, then, is to set position to 0, which is the initial position. This is the difference between the three of them; hold a chestnut:/* filechannel fc=new FileInputStream ("Demo.txt"). Getchannel ();//demo.txt is a file on your local bytebuffer Buff=bytebuffer.allocate (1024);//1024 of this is the capacity fc.read (buff) of buffer, or read the content read from the stream into buffer//1.flip if you are using Flip, That is, the position is set to 0,limit to the current position, the output is the content of Demo.txt//buff.flip (); 2.rewind if the rewind, that is, just set the position to 0, and does not change the limit, if the original limit where the output of the file (limit default at the end of the buffer), the output will be the entire buffer content// Buff.rewind (); Output buffer, where decoding is required to correctly display System.out.println (Charset.forname ("encoding"). Decode (buff)); System.out.println (); */
The flip of buffer and rewind