Here you can find the source of getPathProperty(Properties props, String propName)
Parameter | Description |
---|---|
propName | Property name |
Parameter | Description |
---|---|
Exception | Property is either not specified or the path is invalid |
public static Path getPathProperty(Properties props, String propName) throws Exception
//package com.java2s; //License from project: Open Source License import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Properties; public class Main { /**//from w w w . j a v a 2s. c o m * Gets a property (in Path) from config.properties * * @param propName Property name * @return Property path * @throws Exception Property is either not specified or the path is invalid */ public static Path getPathProperty(Properties props, String propName) throws Exception { String strValue; Path path; // gets the string property try { strValue = getProperty(props, propName); } catch (Exception e) { throw e; } // initializes the path try { path = Paths.get(strValue); } catch (InvalidPathException ipe) { throw new Exception(propName + " is not a valid path."); } return path; } /** * Gets a property (in String) from config.properties * * @param propName Property name * @return Property value * @throws Exception Property is not specified */ public static String getProperty(Properties props, String propName) throws Exception { String value = props.getProperty(propName); // if the propName is not specified if (value == null) { throw new Exception(propName + " must be specified in config.properties."); } return value; } }