title: Finding the last modified file older than 24 hours in Java
body: <p>I'm wanting to send an alert if the latest modified file in a directory is older than 24 hours. I've used the tips from these two questions:</p>
  
  <p><a href="https://stackoverflow.com/questions/2064694/how-do-i-find-the-last-modified-file-in-a-directory-in-java">How do I find the last modified file in a directory in Java?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/8833399/changing-java-date-one-hour-back">Changing Java Date one hour back</a></p>
  
  <p>and have come up with:</p>
  
  <pre><code>File dir = new File("/path/to/dir");
  
  File[] files = dir.listFiles();
  if (files.length == 0) {
      return null;
  }
  
  File lastModifiedFile = files[0];
  for (int i = 1; i &lt; files.length; i++) {
     if (lastModifiedFile.lastModified() &lt; files[i].lastModified()) {
           Date modifiedDate = new Date(files[i].lastModified());
          return modifiedDate;
     }
  }
  Date currentDate = new Date();
  Calendar cal = Calendar.getInstance();
  cal.setTime(currentDate);
  cal.add(Calendar.HOUR, -24);
  Date alertDate = cal.getTime();
  
  if (modifiedDate.before(alertDate)){
      return true;
  } else {
      return false;
  }
  </code></pre>
  
  <p>However I'm getting a "can not find symbol" modifiedDate. I realise that its because modifiedDate can't be seen by the last if statement but if I put that and the alertDate within the initial for loop then I get a "missing return statement". </p>
  
  <p>Any ideas?</p>