Checked exceptions and File.exists() in Java
<p>I have primarily a C# background (and am very much a newbie) so forgive me if my assumptions based on this are the problem.</p>

<p>Simply put, one of the features in a piece of software I'm working on (in Java) has the user input a file name. What I intend to do is have the program loop and append a string to the end of the file name from an array of possible append strings, to see if a file exists, and if it does, open it. I am guaranteed to have only ONE file of a given name, so breaking out of the loop on the first success isn't a bug (if the file name the user specifies is "foo" and the appendStrings array has "bar" and "baz" inside of it, I am guaranteed there will never be both a "foobar" and "foobaz" in the directory). What I eventually came up with was similar to this:</p>

<pre><code>public FileReader LocateFile(String fileName)
{
    FileReader toReturn = null;
    for(int i = 0; i &lt; appendStrings.length; i++)
    {
        File locatedFile = new File(fileName + appendStrings[i]);
        try
        {
            toReturn = new FileReader(locatedFile);
        }
        catch(FileNotFoundException ex)
        {
            continue;
        }
    }
    //...handling in case I didn't find a file.
}
</code></pre>

<p>Great, it works just fine. Except for two problems:</p>

<ol>
<li>The compiler is upset with me that I'm declaring a variable (ex) that I'm not using. I suppose I could log the exception or something, but that seems ridiculous because this will happen often and I'd rather not fill my log file with excessive noise just to make the compiler happy.</li>
<li>I've read from countless sources that you don't use exceptions to control the flow of the program; you use them for <em>exceptional</em> circumstances.</li>
</ol>

<p>My question is: is there a way to please the compiler in this situation? I <em>have</em> to catch that FileNotFoundException, so using File.exists() won't really solve my problem. Am I doing things backwards, or is this just how Java rolls?</p>
