List of utility methods to do Path File Name nio
String | getQualifiedName(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]); ... |
File | getRelativePathFile(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(); |
String | getRelativePathName(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(); |
Path | getResourcePath(Class> resourceClass, String resourceName) get Resource Path URL url = resourceClass.getResource(resourceName);
return Paths.get(url.toURI());
|
Path | getResourceRootPath(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); |
Path | getRoot(final String pathName) get Root return getPathObject(pathName).getRoot();
|
Path | getRootPathFromDirectory(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) { ... |
String | getSimpleName(String path) Get the name of a file. return getSimpleName(Paths.get(path));
|
Path | getSolrCorePath(Path solrHome, String indexName) get Solr Core Path Path corePath = Paths.get(solrHome.toString(), indexName);
return corePath;
|
String | getSourceRoot(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))); ... |