code: public static void deleteOldFiles(String dirPath, int olderThanMinute)  {
  
          File folder = new File(dirPath);
          if (folder.exists()) {
              File[] listFiles = folder.listFiles();
              long eligibleForDeletion = System.currentTimeMillis() - (olderThanMinute * 60 * 1000L);
              for (File listFile: listFiles) {
                  if (listFile.lastModified() < eligibleForDeletion) {
                      if (!listFile.delete()) {
                          logger.error("Unable to delete file %s", listFile);
                      }
                  }
              }
          }
      }
docs: Delele old files
  
  @param dirPath path of the filesystem
  @param olderThanMinute the minutes that defines older files