Originally posted by Siddharth bal sharma:
easiest but not the correct way.
That's rather strong. If it works, how can it not be "correct"?
I agree that under normal circumstances, using exceptions for
testing is a Bad Thing (I loathe that ObjectInputStream/ObjectOutputStream signals EOF with an exception). However, you need some functionality. Someone has already implemented that functionality in the API. Does it really matter that you have to break convention to use it? I don't think so. If it does, then maybe someone else has a better idea (I don't).
As for performance, unless your app is churning through hundreds of files and users are waiting for them, I don't think it matters that it takes a few milliseconds to set up the try block in this case.