Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7862135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:00:45+00:00 2026-06-02T23:00:45+00:00

file = new RandomAccessFile(xanadu.txt, rw); FileChannel channel = file.getChannel(); ByteBuffer buffer = ByteBuffer.allocate(48); int

  • 0
 file = new RandomAccessFile("xanadu.txt", "rw");
        FileChannel channel = file.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(48);
        int byteReads = channel.read(buffer);

SO I am allocating 48 as a capacity in the Buffer. Now
consider the txt file I am reading is of about 10MB , so logically it is crossing the buffer allocation size.
But when we try to read, we will be able to read all the contents of the file despite the size.
SO how this thing is possible.

I am new to this streaming field so may be my question seems to be very basic.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:00:48+00:00Added an answer on June 2, 2026 at 11:00 pm

    The read call simply won’t read more than 48 bytes.

    Nothing will overflow, you’ll just need to call read repeatedly until you’ve read all the data you’re expecting.

    This is stated in the ReadableByteChannel interface docs:

    Reads a sequence of bytes from this channel into the given buffer.

    An attempt is made to read up to r bytes from the channel, where r is the number of bytes remaining in the buffer, that is, dst.remaining(), at the moment this method is invoked.

    You need to clear() the buffer after processing its content before passing it back to read.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am mapping a file("sample.txt") to memory using FileChannel.map() and then closing the channel
Consider some code that calls, say, file = new RandomAccessFile(x, r); file.getChannel().map(....) and wants
I am using following code to read a sub-sequence from a file. FileChannel channel
I have: o = File.new(ouput.txt, rw+) File.new(my_file.txt).lines.reverse_each { |line| ????? line } o.close I
Hi I have some code that uses block RandomAccessFile file = new RandomAccessFile(some file,
Consider I have a file new.txt like, asdfg qwerty zcx poi Now i need
I'm using RandomAccessFile in java: file = new RandomAccessFile(filename, rw); ... file.writeBytes(...); How can
In VS2008, I go to File/New/Project, select ASP.NET Web Application and create a new
File file = new File(file-type-string-i-want-2000-01-01-01-01-01.conf.gz); Matcher matcher = pattern.compile(\\-(.*)\\-\\d{4})).matcher(fileName); StringBuilder sb = new StringBuilder();
I added a new file F1 and made changes to another file F2 but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.