Java Utililty Methods Path File Name nio

List of utility methods to do Path File Name nio

Description

The list of methods to do Path File Name nio are organized into topic(s).

Method

PathgetAbsolutePath(String name)
get Absolute Path
return Paths.get(name).toAbsolutePath();
StringgetAbsolutePathName(File dir)
get Absolute Path Name
try {
    return getAbsolutePath(dir).toString();
} catch (IOException e) {
    return dir.getAbsolutePath();
ListgetAllFiles(List fileNames, Path path)
Collect all the files in a given path recursively
try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
    for (Path subPath : stream) {
        if (subPath.toFile().isDirectory()) {
            getAllFiles(fileNames, subPath);
        } else {
            String fileName = subPath.toAbsolutePath().toString();
            fileNames.add(fileName);
} catch (IOException e) {
    throw e;
return fileNames;
StringgetArtifactName(Path artifactPath)
utility method which returns the name of the web artifact specified
String artifactFileName = artifactPath.getFileName().toString();
return artifactFileName.substring(0, artifactFileName.length() - 4);
StringgetBandNameStr(Path filePath)
Get the band name string from the specified filepath.
String fileNameStr = filePath.getFileName().toString();
Matcher m = LANDSAT_BAND_PATTERN.matcher(fileNameStr);
if (m.matches()) {
    return m.group(1);
throw new IllegalArgumentException(String.format("Could not find band name in file name %s.", fileNameStr));
StringgetClassName(Path pluginImplementationDirectory, Path classFile)
get Class Name
String className = pluginImplementationDirectory.relativize(classFile).toString()
        .replace(JAR_DIRECTORY_SEPARATOR, PACKAGE_SEPARATOR).replace(CLASS_FILE_EXTENSION, "");
if (className.startsWith(PACKAGE_SEPARATOR) && className.length() > 1) {
    className = className.substring(1);
return className;
PathgetConfigurationFile(String installPath, String serverName)
get Configuration File
Path curServerPath = getServerDir(installPath, serverName);
return curServerPath.resolve(SERVER_CONFIG_FILE);
PathgetConfigurationFilePath(String name)
get Configuration File Path
return getConfigurationDirectoryPath().resolve(name);
PathgetContentPath(Path zipFilePath, String contentFileName)
get Content Path
try {
    FileSystem zipFile = FileSystems.newFileSystem(zipFilePath, null);
    Path packagedPath = zipFile.getPath(contentFileName);
    if (Files.exists(packagedPath)) {
        return packagedPath;
    } else {
        return null;
} catch (IOException e) {
    throw new RuntimeException(e);
PathgetDatabaseDirectoryPath(String databaseDirectory, String name)
get Database Directory Path
if (Paths.get(databaseDirectory).isAbsolute()) {
    return Paths.get(databaseDirectory, name);
} else {
    return Paths.get(getProperty("user.dir"), databaseDirectory, name);