ByteBuffer: rewind() : ByteBuffer « java.nio « Java by API






ByteBuffer: rewind()

   
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class MainClass {
  public static void main(String args[]) {
    FileInputStream fIn;
    FileChannel fChan;
    long fSize;
    ByteBuffer mBuf;

    try {
      fIn = new FileInputStream("test.txt");

      fChan = fIn.getChannel();

      fSize = fChan.size();

      mBuf = ByteBuffer.allocate((int) fSize);

      fChan.read(mBuf);

      mBuf.rewind();

      for (int i = 0; i < fSize; i++)
        System.out.print((char) mBuf.get());
      fChan.close();
      fIn.close();
    } catch (IOException exc) {
      System.out.println(exc);
    }
  }
}

           
         
    
    
  








Related examples in the same category

1.ByteBuffer: allocate(int capacity)
2.ByteBuffer: allocateDirect(int size)
3.ByteBuffer: asCharBuffer()
4.ByteBuffer: asDoubleBuffer()
5.ByteBuffer: asFloatBuffer()
6.ByteBuffer: asLongBuffer()
7.ByteBuffer: asShortBuffer()
8.ByteBuffer: capacity()
9.ByteBuffer: clear()
10.ByteBuffer: compact()
11.ByteBuffer: flip()
12.ByteBuffer: get()
13.ByteBuffer: get(byte[] dst, int offset, int length)
14.ByteBuffer: get(int index)
15.ByteBuffer: getChar()
16.ByteBuffer: getDouble()
17.ByteBuffer: getFloat()
18.ByteBuffer: getInt()
19.ByteBuffer: getLong()
20.ByteBuffer: isDirect()
21.ByteBuffer: limit()
22.ByteBuffer: order()
23.ByteBuffer: order(ByteOrder bo)
24.ByteBuffer: position()
25.ByteBuffer: position(int newPosition)
26.ByteBuffer: put(byte b)
27.ByteBuffer: putChar(char ch)
28.ByteBuffer: putDouble(double value)
29.ByteBuffer: putFloat(float value)
30.ByteBuffer: putInt(int i)
31.ByteBuffer: putLong(long value)
32.ByteBuffer: putShort(short value)
33.ByteBuffer: putShort(int index, short value)
34.ByteBuffer: wrap(byte[] array)