• Post Reply Bookmark Topic Watch Topic
  • New Topic

Speeding up BufferedReader

 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an applet that reads a file from the server using BufferedReader.readLine(). This method of reading is kind of slow. Is there any techniques on improving the speed of reading data through BufferedReader?
thanks,
Alex
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main one is to use read(char[]) instead. This way to avoid creating a new String object for each line, which can be tiresome. However, it really depends on what sort of processing you want to do with each line. If you end up having to create lots of other Strings anyway, this won't make much of a difference.
Try this: write a loop that does nothing but read each and every line of your file, using BufferedReader and readLine(). Time it. Then do the same using read(char[]) instead - keep reading char arrays until it returns -1. Now compare the times you get here with the times you get when you do whatever other processing you're doing on each line. This will give you an idea how much benefit you can get from changing techniques.
 
Mahesh Mamani
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This Java Tip should be useful for improving I/O performance.JDC Tech Tip

Hope It Helps

MSM
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!