public String readPasswordFromFile(String filePath, String defaultPassword) {
    if (StringUtils.isBlank(filePath) || !fileExistsAndCanBeRead(filePath)) {
      LOG.debug("DB password file not specified or does not exist/can not be read - using default");
      return defaultPassword;
    } else {
      LOG.debug("Reading password from file {}", filePath);
      String password = null;
      try {
        password = FileUtils.readFileToString(new File(filePath), Charset.defaultCharset());
        return StringUtils.chomp(password);
      } catch (IOException e) {
        throw new RuntimeException("Unable to read password from file [" + filePath + "]", e);
      }
    }
  }
Reading password from the given password file

@param filePath
         the path of the file to read the password from
@param defaultPassword
         the default password this function returns in case the given
         <code>filePath</code> is <code>blank</code> or the password file
         cannot be read for any reason
@return the password found in the given password file or
        <code>defaultPassword</code> if the given path is <code>blank</code>
        or cannot be read for any reason
@throws RuntimeException
          when any error occurred while reading the password file
ambari-server/src/main/java/org/apache/ambari/server/utils/PasswordUtils.java