title: Java: Efficient way to scan a folder for a particular file
body: <p>I am contacting an external services with my Java app. </p>
  
  <p>The flow is as follow: ->I generate an XML file, and put it in an folder, then the service processes the file and return another file with the same name having an extension <code>.out</code></p>
  
  <p>Right now after I put the file in the folder I start with a loop, until I get that file back so I can read the result.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>        fileName += ".out";
          File f = new File(fileName);
          do
          {
              f = new File(fileName);
          } while (!f.exists());
  
          response = readResponse(fileName); // got the response now read it
  </code></pre>
  
  <p>My question comes here, am I doing it in the right way, is there a better/more efficient way to wait for the file?</p>
  
  <p>Some info: I run my app on WinXP, usually it takes the external service less than a second to respond with a file, I send around 200 request per day to this services. The path to the folder with the result file is always the same.</p>
  
  <p>All suggestions are welcome.</p>
  
  <p>Thank you for your time.</p>