Home Tutorial Java Corejava Nio Java MappedByteBuffer example, How to create mapped byte buffer in java.

 
 

Java MappedByteBuffer example, How to create mapped byte buffer in java.
Posted on: August 13, 2010 at 12:00 AM
Advertisement
In this tutorial, you will see how to create mapped byte buffer in java.

Java MappedByteBuffer example, how to create mapped byte buffer in java.

In this tutorial, you will see how to create mapped byte buffer in java.

Code

import java.nio.*;
import java.nio.channels.FileChannel;
import java.io.*;

public class CreateMapBuffer {
  public static void main(String[] argsthrows IOException  {    
File file=new File("FileTest.txt");
FileInputStream fin=new FileInputStream(file);
FileChannel fc=fin.getChannel();
MappedByteBuffer mapByteBuff=fc.map(FileChannel.MapMode.READ_ONLY,
 
0, file.length() );
 while (mapByteBuff.hasRemaining())
 {
   System.out.print((char)mapByteBuff.get());
}
 System.out.println();
 if(mapByteBuff.isReadOnly())
 {
   System.out.print("MappedByteBuffer is read only");
 }else
 {
   System.out.print("MappedByteBuffer is not read only");
 }
}
}

Output

C:\>java CreateMapBuffer
RoseIndia
MappedByteBuffer is read only

Download this code

Advertisement

Related Tags for Java MappedByteBuffer example, How to create mapped byte buffer in java.:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 13, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com