MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

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

public class MainClass {
    public static void main(String[] args) throws Exception {
        File aFile = new File("charData.xml");
        FileInputStream inFile = null;

        inFile = new FileInputStream(aFile);

        FileChannel inChannel = inFile.getChannel();
        ByteBuffer buf = ByteBuffer.allocate(48);

        while (inChannel.read(buf) != -1) {
            System.out.println("String read: " + ((ByteBuffer) (buf.flip())).asCharBuffer().get(0));
            buf.clear();
        }
        inFile.close();
    }
}