code: public static File getWritableDirectoryWithFailovers(String... directories) throws FileNotFoundException {
      File logDir = null;
      for(String directory : directories) {
        if(directory != null) {
          try {
            logDir = ensureDirectoryWriteable(new File(directory));
          } catch(FileNotFoundException e) {
            log.debug("Failed to get writeable directory: "+directory, e);
            continue;
          }
          break;
        }
      }
      if(logDir == null) {
        throw new FileNotFoundException("Could not get a writeable directory!");
      }
      return logDir;
    }
docs: Gets the first writable directory that exists or can be created.
  @param directories The directories to try
  @return A File object that represents a writable directory.
  @throws FileNotFoundException Thrown if no directory can be written to.