List of utility methods to do Path File Name nio
String | fileName(final Path thePath) file Name return fileName(thePath.getFileName().toString());
|
Path | filterJarContainingClass(Collection filter Jar Containing Class for (File file : jarsPaths) { JarFile jarFile = new JarFile(file); if (containsClass(jarFile, className)) { return file.toPath(); return null; |
List | findExecutablePaths(String executableName) Locates an executable in the current system. return findExecutablePaths(executableName, Integer.MAX_VALUE);
|
Path | findFile(Path directoryPath, String fileName) find File File[] files = directoryPath.toFile().listFiles(); if (files != null) { for (File file : files) { if (file.isFile()) { if (file.getName().equals(fileName)) { return file.toPath(); } else if (file.isDirectory()) { ... |
File | findFile(String basePath, final String fileName) TODO dir cache Path startPath = Paths.get(basePath); final List<File> fileResult = new ArrayList<>(); Files.walkFileTree(startPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { return FileVisitResult.CONTINUE; @Override ... |
String | findNextFileName(Path folder, String name) find Next File Name Path file = folder.resolve(name); if (!Files.exists(file)) { return name; String a = getNamePart(file); String b = getExtPart(file); if (b.length() > 0) { b = "." + b; ... |
Path | findRootPathForResource(String resourceName, ClassLoader classLoader) Find the root path for the given resource. Objects.requireNonNull(resourceName, "resourceName"); Objects.requireNonNull(classLoader, "classLoader"); URL resource = classLoader.getResource(resourceName); if (resource != null) { String protocol = resource.getProtocol(); if (protocol.equals("jar")) { return getJarPathFromUrl(resource); } else if (protocol.equals("file")) { ... |
Optional | findUpward(String filename, Path startingPath) Find a file with the given base name, searching upward from the given starting directory. Preconditions.checkNotNull(filename); Preconditions.checkArgument(!filename.contains(File.separator)); Preconditions.checkArgument(Files.isDirectory(startingPath)); Path possibleRootDir = startingPath; while (possibleRootDir != null) { Path possiblePath = possibleRootDir.resolve(filename); if (Files.isRegularFile(possiblePath)) { return Optional.of(possiblePath); ... |
String | formatPathName(Path path) Format the file/diretory information as specified in RFC int thisYear, node = 1; Locale fileLocale = new Locale("en"); String user = "user", group = "group"; String dateString, permission; GregorianCalendar fileDate = new GregorianCalendar(); thisYear = fileDate.get(Calendar.YEAR); if (Files.isDirectory(path)) permission = "d---------"; ... |
String | getAbsolutePath(String fileName) Returns the absolute path to a file with name fileName
return Paths.get(fileName).toAbsolutePath().toString();
|