Home Tutorial Java Corejava Nio Java MappedByteBuffer example, How to create a large size file in java.

 
 

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

Java MappedByteBuffer example, How to create a large file in java.

In this tutorial, you will see how to create a large file with the help of MappedByteBuffer class in java.

Code

import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
            
public class CreateFile{
  public static void main(String[] argsthrows Exception {
    RandomAccessFile out = new RandomAccessFile("test.txt""rw");
    FileChannel fc = out.getChannel();
    int length = 0x8FFFAA;
MappedByteBuffer MappByteBuff = fc.map(FileChannel.MapMode.READ_WRITE,
        0, length);
    for (int i = 0; i < length; i++)
    {
      MappByteBuff.put((byte'B');
    }
    System.out.println("File successFully written");
  }
}

Output

C:\>java CreateFile
File successFully written

Download this code

Advertisement

Related Tags for Java MappedByteBuffer example, How to create a large size file 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