Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Fastest File Read Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Fastest File Read Method" Watch "Fastest File Read Method" New topic
Author

Fastest File Read Method

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
I am reading from a file and printing it to a screen.
Currently I do this:

*********************************
What is the fastest way, or at least a faster way?
Keep in mind I only need to read and write ascii with this method, so bascially html & txt files. No binary.
[ April 24, 2002: Message edited by: Dirk Schreckmann ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
Check out BufferedReader and BufferedWriter classes.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Using the Buffered classes at all will give you your first notable improvement - then, figure out how to use the read(char[]) and write(char[], int, int) methods to read/write a group of characters at once. Also, there's no need to build a big String ("thisFile") with all the chars together in it at once - just write each char[] group to your output stream as you go. If you do need to get everything in one big String, try using a StringBuffer instead of String for thisFile.


"I'm not back." - Bill Harding, Twister
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Fastest File Read Method