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

StringgetQualifiedName(String outputDir, Path path)
Returns a dot separated name of the file represented by the given path without its fileextension Example: outputdir is /a/b and path represents /a/b/c/d/e.txt returns "c.d.e"
StringBuilder qualifiedName = new StringBuilder(path.getName(0).toString());
for (int i = 1; i < path.getNameCount() - 1; i++) {
    qualifiedName.append(".");
    qualifiedName.append(path.getName(i));
if (path.getFileName() != null) {
    String[] seperatedFileName = path.getFileName().toString().split("\\.");
    qualifiedName.append("." + seperatedFileName[0]);
...
FilegetRelativePathFile(String fileName)
Makes provided path relative to the current working directory.
Path filePath = Paths.get(fileName);
if (filePath.isAbsolute()) {
    Path currentPath = Paths.get(".");
    return currentPath.relativize(filePath).toFile();
} else
    return filePath.toFile();
StringgetRelativePathName(Path root, Path path)
Returns a relative and normalized name for a Path .
Path relative = root.relativize(path);
return Files.isDirectory(path) && !relative.toString().endsWith("/")
        ? String.format("%s/", relative.toString())
        : relative.toString();
PathgetResourcePath(Class resourceClass, String resourceName)
get Resource Path
URL url = resourceClass.getResource(resourceName);
return Paths.get(url.toURI());
PathgetResourceRootPath(Class resourceClass, String resourceName)
get Resource Root Path
URL url = resourceClass.getResource(resourceName);
try {
    return Paths.get(url.toURI()).getParent();
} catch (URISyntaxException e) {
    throw new IllegalStateException(e);
PathgetRoot(final String pathName)
get Root
return getPathObject(pathName).getRoot();
PathgetRootPathFromDirectory(String resourceName, URL resource)
get Root Path From Directory
try {
    Path result = Paths.get(resource.toURI());
    int relativePathSize = Paths.get(resourceName).getNameCount();
    for (int i = 0; i < relativePathSize; i++) {
        result = result.getParent();
    return result;
} catch (URISyntaxException e) {
...
StringgetSimpleName(String path)

Get the name of a file.

return getSimpleName(Paths.get(path));
PathgetSolrCorePath(Path solrHome, String indexName)
get Solr Core Path
Path corePath = Paths.get(solrHome.toString(), indexName);
return corePath;
StringgetSourceRoot(Path filePath, String pkgName)
get Source Root
if (filePath == null || filePath.getParent() == null) {
    return null;
Path parentPath = filePath.getParent();
if (parentPath == null) {
    return null;
List<String> pathParts = Arrays.asList(parentPath.toString().split(Pattern.quote(File.separator)));
...