Java Utility Get Integer Value From Properties File

Load the property File

Properties prop = new Properties();
   String propFileName = "/opt/";
   try(InputStream inputStream = new FileInputStream(propFileName)) {

Now get the Integer Value from the loaded property File

	 * @param prop
	 * @param propertyNameInFile
	 * @param defaultValue
	 * @return the value from the file or the default value
	private static int getIntegerValueFromFile(Properties prop, String propertyNameInFile, int defaultValue) {

		String propertyValueInFile = prop.getProperty(propertyNameInFile);
		int value = defaultValue;
		if (StringUtils.isNotBlank(propertyValueInFile)) {
			try {
				value = Integer.parseInt(propertyValueInFile);
			} catch (Exception e) {
				logger.error(e, e);
		return value;

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.