Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Fastest way to read a 5MB textfile (200,000 lines)?

807591May 15 2008 — edited May 16 2008
My current code:
String file = "";
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
while(in.ready()) file = file.concat(in.readLine());
Unfortunately it is awfully slow (starting with 2,000 lines per second but dropping to like 100 lines per second over time). What is the fastest way to load the content of that file in a string and out of curiosity, why are my lines per second dropping?

Thank you for your help!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 13 2008
Added on May 15 2008
15 comments
667 views