Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.File;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Main {
    public static void main(String[] argv) throws Exception {
        File file = new File("filename");
        FileChannel roChannel = new RandomAccessFile(file, "r").getChannel();
        ByteBuffer readonlybuffer = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, (int) roChannel.size());

        FileChannel rwChannel = new RandomAccessFile(file, "rw").getChannel();
        ByteBuffer writeonlybuffer = rwChannel.map(FileChannel.MapMode.READ_WRITE, 0, (int) rwChannel.size());

        // Create a private (copy-on-write) memory-mapped file.
        FileChannel pvChannel = new RandomAccessFile(file, "rw").getChannel();

        ByteBuffer privatebuffer = roChannel.map(FileChannel.MapMode.READ_WRITE, 0, (int) rwChannel.size());

    }
}