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.
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[] args) throws 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