Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading File in a Buffer  RSS feed

 
Nikhil Bansal
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Thx for reading the post.

I do have a huge file with size greater than 50MB. I need to read the 1st 5 MB of file, process it and then read next 5MB and so on.

Any inputs are much appreciated.

Regards

Nikhil Bansal
 
Scott Selikoff
author
Bartender
Posts: 4093
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, check out the java almanac tutorial for basic setup:

http://javaalmanac.com/egs/java.io/File2ByteArray.html?l=rel

You should then read through the FileInputStream API:

http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileInputStream.html

The change you'll need to make is that instead of creating an array the size of 'length' create one the size of the chunk you want to read, such as 5 megabytes. Then, just add a loop that keeps reading 5 megabyte chunks until the file is completely read.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!