aspose file tools*
The moose likes I/O and Streams and the fly likes Reading large txt files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Reading large txt files" Watch "Reading large txt files" New topic
Author

Reading large txt files

saivenkat venkatesan
Greenhorn

Joined: Aug 11, 2006
Posts: 14
May i know the efficient way of using IO to read the LARGE SIZE of txt files? which IO we can use
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18163
    
    8

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

Joined: Aug 11, 2006
Posts: 14
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
Bartender

Joined: Oct 14, 2005
Posts: 18163
    
    8

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

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading large txt files
 
Similar Threads
problem with reading and writing toa files
Text Search on a file from a JSP page?????
copying contents of one file to another
HttpServletResponse.getOutputStream() - streaming or not streaming?
Shell scripts find n replace the word in files