Java Path File Name nio getPathProperty(Properties props, String propName)

Here you can find the source of getPathProperty(Properties props, String propName)

Description

Gets a property (in Path) from config.properties

License

Open Source License

Parameter

Parameter Description
propName Property name

Exception

Parameter Description
Exception Property is either not specified or the path is invalid

Return

Property path

Declaration

public static Path getPathProperty(Properties props, String propName) throws Exception 

Method Source Code


//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;
    }
}

Related

  1. getPathByFormat(String nameBeforeDot, String nameAfterDot, Path parent, int i, String date)
  2. getPathCleanName(Path object)
  3. getPathInTmpDir(String fileName)
  4. GetPathName(String path)
  5. getPathOfClass(Class cls, String filename)
  6. getPaths(Path dir, String fileNames)
  7. getPrefix(final Path file, final int filenameSuffixLength)
  8. getPrintWriter(String className, String flushPath)
  9. getProvenanceLogFiles(final String baseName, final Collection allProvenanceLogs)