Or, skip saving things in Strings or StringBuffers entirely, and write your output directly to the Writer bw. OK, you'll have to save somethings along the way, but many things are not necessary. I'd just read one line from the file, process it, and write the results to the Writer before moving on.
To be fair, this sort of performance optimization is less important than getting the logic right. Here are some perfectly legal
test cases to consider:
Can you highlight this correctly?
Incidentally, a related discussion may be found
here.
[ April 27, 2002: Message edited by: Jim Yingst ]