"It wastes time?" I think what you're implying here is that allocating objects using Java "new" is a time-consuming operation. First of all, it's not, not really. Java allocators are pretty sophisticated. Second of all, have your got any idea how many orders of magnitude slower disk I/O is than memory allocation? Allocating an object may take a few hundred cycles, at worst. On a 2GHz processor, this is 100 billionths of a second -- a tenth of a microsecond. Disk seek times are measured in milliseconds; 8 ms is typical. This is enough time to allocate 80,000 objects (somebody might want to check my math!) Anyway, what I'm saying is, this is a silly question. To open a file, create a FileReader. Use it, close it, make another one if you need to. Don't worry so much about micro performance issues.
I concur with Ernest here. Newing up an object isn't that big of a deal, unless you are newing up a whole heck of a lot of InputStreams, at which point you don't need to worry about processing, you need to worry about your design. Very few applications I can think of (if any!) are so time dependent that a 10th of a microsecond is a defining factor.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop