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

StringfileName(final Path thePath)
file Name
return fileName(thePath.getFileName().toString());
PathfilterJarContainingClass(Collection jarsPaths, String className)
filter Jar Containing Class
for (File file : jarsPaths) {
    JarFile jarFile = new JarFile(file);
    if (containsClass(jarFile, className)) {
        return file.toPath();
return null;
ListfindExecutablePaths(String executableName)
Locates an executable in the current system.
return findExecutablePaths(executableName, Integer.MAX_VALUE);
PathfindFile(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()) {
...
FilefindFile(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
...
StringfindNextFileName(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;
...
PathfindRootPathForResource(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")) {
...
OptionalfindUpward(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);
...
StringformatPathName(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---------";
...
StringgetAbsolutePath(String fileName)
Returns the absolute path to a file with name fileName
return Paths.get(fileName).toAbsolutePath().toString();