-
FileChannel
I am learning about the FileChannel class.
My code using the FileChannel is:
Code:
String data = "friends.txt";
FileInputStream inData = new FileInputStream(data);
FileChannel inChannel = inData.getChannel();
long inSize = inChannel.size();
ByteBuffer source = ByteBuffer.allocate((int) inSize);
inChannel.read(source, 0);
source.position(0);
System.out.println("Original byte data: ");
for (int i = 0; source.remaining() > 0; i++) {
System.out.print(source.get());
}
I am really confused as to what the benefits are of using the FileChannel class as opposed to using:
FileInputStream and BufferedInputStream classes ?
I might be missing something really obvious.
Thank you
-
-
-