Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading large txt files

 
saivenkat venkatesan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May i know the efficient way of using IO to read the LARGE SIZE of txt files? which IO we can use
 
Paul Clapham
Sheriff
Pie
Posts: 20729
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A BufferedReader is probably the best you can do. No matter what your code does, when you come right down to it the code has to read each of the bytes in the file. So expect the time taken to read the file to be proportional to the file's size.
 
saivenkat venkatesan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read in one of the mail thread that if we use BufferedReader to read large files,the performance will be slowdown since temporarily the data will be strored in the String pool. So is it ok if I use BufferedReader ?
 
Paul Clapham
Sheriff
Pie
Posts: 20729
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't fair to ask me to comment on things that you read somewhere else, especially without posting a link to those things.

However, the only things that are put into Java's string pool are compile-time string constants and strings for which the intern() method has been called. So that's irrelevant to reading data from files. Unless (a definite possibility) what you read was talking about something completely different. As I said, I have no way of knowing.

It's always possible to write bad code. But using a BufferedReader is the standard way to read lines of text from a file. Did whatever you read somewhere else have a better suggestion?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recently saw a post that suggested this:

put every line read into the string pool and would eventually blow out memory. Is that the one you were thinking of? That's not the case; there was a correction further down the thread. You can read forever as long as you're not saving the lines in a collection or something.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic