Results 1 to 4 of 4

Thread: FileChannel

  1. #1
    dewitrydan is offline Member
    Join Date
    Aug 2010
    Posts
    67
    Rep Power
    0

    Default FileChannel

    I am learning about the FileChannel class.
    My code using the FileChannel is:
    Java 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

  2. #2
    dewitrydan is offline Member
    Join Date
    Aug 2010
    Posts
    67
    Rep Power
    0

    Default

    anyone?.........

  3. #3
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    It's faster.
    Sincerely, Joshua Green
    Please REP if I help :)

  4. #4
    dewitrydan is offline Member
    Join Date
    Aug 2010
    Posts
    67
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •