File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Fastest File Read Method" Watch "Fastest File Read Method" New topic

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

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

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

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
I agree. Here's the link:
subject: Fastest File Read Method