MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

/*
 * Output:
     
    
 */

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

public class MainClass {
    public static void main(String[] args) {
        try {
            File aFile = new File("test.txt");

            FileOutputStream outputFile = null;
            outputFile = new FileOutputStream(aFile, true);
            FileChannel outChannel = outputFile.getChannel();

            ByteBuffer buf = ByteBuffer.allocate(200);

            buf.putInt(10).asCharBuffer().put("www.java2s.com");

            buf.position(10).flip();
            outChannel.write(buf);
            buf.clear();

            outputFile.close();

        } catch (Exception e) {
            e.printStackTrace();

        }

    }
}