Java Utililty Methods Path File Extention nio

List of utility methods to do Path File Extention nio

Description

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

Method

StringgetFileNameWithoutExtension(Path path)
Gets the file name of the given path without the extension.
String name = path.getFileName().toString();
int index = name.lastIndexOf('.');
if (index <= 0) {
    return name;
} else {
    return name.substring(0, index);
StringgetFileNameWithoutExtension(Path path)
get File Name Without Extension
if (path == null || Files.isDirectory(path)) {
    return null;
String fileName = path.getFileName().toString();
return fileName.substring(0, fileName.lastIndexOf("."));
StringgetFileNameWithoutExtension(String filePath)
get File Name Without Extension
String name = getFileName(filePath);
return name.replaceFirst("[.][^.]+$", "");
ListgetFilesList(Path directory, Set extensions)
get Files List
try (Stream<Path> stream = Files.list(directory)) {
    List<Path> list = stream.filter(path -> extensions.contains(getFileExtension(path)))
            .collect(Collectors.toList());
    return list;
StringgetFullNameWithoutExtension(Path f)
get Full Name Without Extension
String path = f.toString();
return getFullNameWithoutExtension(path);
StringgetLeafName(Path path, boolean includeExtension)
get Leaf Name
return getLeafName(path.toString(), includeExtension);
ListgetListOfFilesByExtension(Path directoryPath, Set extensions)
get List Of Files By Extension
List<Path> result = new ArrayList<>();
DirectoryStream.Filter<Path> filter = (fileEntry) -> {
    return extensions.contains(com.google.common.io.Files.getFileExtension(fileEntry.toString()));
};
try (DirectoryStream<Path> stream = Files.newDirectoryStream(directoryPath, filter)) {
    for (Path file : stream) {
        result.add(file);
return result;
PathgetPath(String outputDir, String qualifiedFilename, String fileextension)
get Path
String[] pathParts = qualifiedFilename.split("\\.");
pathParts[pathParts.length - 1] = pathParts[pathParts.length - 1] + "." + fileextension;
return FileSystems.getDefault().getPath(outputDir, pathParts);
StringgetTransformedOutputPath(Path input, String compressExtension, String outputDir)
get Transformed Output Path
return Paths.get(outputDir).resolve(input) + ".variants.json" + compressExtension;
booleanhasExtensionIgnoreCase(Path path, String ext)
has Extension Ignore Case
String name = path.getFileName().toString();
int dot = name.lastIndexOf('.');
String token = name.substring(dot + 1);
if (token == null)
    return false;
return token.equalsIgnoreCase(ext);