Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I read large file effeciently.....?  RSS feed

 
Naveen Raja
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I am trying to read large file content with following piece of code. But its utlizing more memory

FileReader file = new FileReader(args[0]);

input = new BufferedReader(file);

Is there any way other than increasing HEAP SIZE...?


Thanks a lot....
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you read x amount of data, it will displace at least x amount of memory (there's additional overhead in Unicode encoding and object housekeeping). The only workaround is to read in a chunk of data, process it, then read in more.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!