MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

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

public class MainClass {
    public static void main(String args[]) {
        FileOutputStream fileOutputStream;
        FileChannel fileChannel;
        ByteBuffer byteBuffer;

        try {
            fileOutputStream = new FileOutputStream("test.txt");
            fileChannel = fileOutputStream.getChannel();
            byteBuffer = ByteBuffer.allocateDirect(26);

            for (int i = 0; i < 26; i++)
                byteBuffer.put((byte) ('A' + i));
            byteBuffer.rewind();
            fileChannel.write(byteBuffer);
            fileChannel.close();
            fileOutputStream.close();
        } catch (IOException exc) {
            System.out.println(exc);
        }
    }
}