Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Reading large txt files

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 27290
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 27290
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic