GeeCON Prague 2014*
The moose likes I/O and Streams and the fly likes best method to read a long file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "best method to read a long file" Watch "best method to read a long file" New topic
Author

best method to read a long file

Gaurav-new-to-java
Greenhorn

Joined: Oct 17, 2002
Posts: 1
Hi , what the best method to read a file ( really really long )
Sam Moran
Ranch Hand

Joined: Sep 28, 2002
Posts: 86
If you are talking about a text file you have to read it line-by-line no matter what!

I hope this helps?!?!?
[ October 17, 2002: Message edited by: Sam Moran ]

We make a living by what we get, we make a life by what we give!
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
Originally posted by Sam Moran:
If you are talking about a text file you have to read it line-by-line no matter what!

Actually you can read files in whatever size chunks you want -- lines or no lines, text or binary. Readers should only be used for text, and InputStreams can be used for anything. You can consult the java documentation for details on their usage. Here's a common idiom:
Steve Deadsea
Ranch Hand

Joined: Dec 03, 2001
Posts: 125
The best way to read a file of any size is using buffers. You can either use a buffered wrapper class or do the buffering yourself.
 
Don't get me started about those stupid light bulbs.
 
subject: best method to read a long file