FileInputStream: getChannel() : FileInputStream : java.io : Java by API examples (example source code) Organized by topic

Java by API
C++
PHP
Java by API Home »  java.io   » [  FileInputStream  ]   
 



FileInputStream: getChannel()

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

public class MainClass {
  public static void main(String args[]) {
    FileInputStream fIn;
    FileChannel fChan;
    long fSize;
    ByteBuffer mBuf;

    try {
      fIn = new FileInputStream("test.txt");

      fChan = fIn.getChannel();

      fSize = fChan.size();

      mBuf = ByteBuffer.allocate((intfSize);

      fChan.read(mBuf);

      mBuf.rewind();

      for (int i = 0; i < fSize; i++)
        System.out.print((charmBuf.get());
      fChan.close();
      fIn.close();
    catch (IOException exc) {
      System.out.println(exc);
    }
  }
}

           
       
Related examples in the same category
1.  new FileInputStream(String name)
2.  FileInputStream: available()
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.