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

StringgetFileExtension(final Path file)
get File Extension
if (file == null) {
    return "";
} else {
    final String fileName = file.toString();
    return getFileExtension(fileName == null ? "" : fileName);
StringgetFileExtension(final Path path)
Return the extension of the file.
Strip all the parent folders and the name of the file to return just the file extension.
Objects.requireNonNull(path);
if (Files.isDirectory(path)) {
    throw new IllegalArgumentException("Cannot get extension of a directory");
final String filename = path.getFileName().toString();
final int extensionSeparatorIndex = filename.lastIndexOf(FILE_EXTENSION_SEPARATOR);
if (extensionSeparatorIndex <= 0) {
    return "";
...
OptionalgetFileExtension(Path file)
Returns the extension of a file or Optional.empty() if the file does not have one (no .
return getFileExtension(file.toString());
StringgetFileextension(Path path)
Returns the fileextension of the file represented by the given path Example: outputdir is /a/b and path represents /a/b/c/d/e.txt.tmp returns txt.tmp
String fileextension = null;
String fullFileName = (path.getFileName() == null) ? "" : path.getFileName().toString();
if (fullFileName.contains(".")) {
    fileextension = fullFileName.substring(fullFileName.indexOf(".") + 1);
return fileextension;
StringgetFileExtension(Path path)
get File Extension
String fileNameWithExt = path.getName(path.getNameCount() - 1).toString();
int index = fileNameWithExt.lastIndexOf('.');
if (index != -1)
    return fileNameWithExt.substring(index + 1);
else
    return null;
StringgetFileExtension(Path path)
Gets the file extension of the given path.
String ext = path.getFileName().toString();
int index = ext.lastIndexOf('.');
if (index <= 0) {
    return "";
} else {
    return ext.substring(index, ext.length());
StringgetFileExtension(Path path)
Herausfiltern einer Dateiendung
String fileName = path.getFileName().toString(); 
return fileName.lastIndexOf('.') == -1 ? "" : fileName.substring(fileName.lastIndexOf('.'));
StringgetFileExtension(Path path)
get File Extension
String fname = path.getFileName().toString();
return fname.substring(fname.lastIndexOf('.') + 1);
StringgetFileNameNoExtensionFromPath(String modulePath)
Gets the name of the module, minus the windows file extension if on Windows
Path path = Paths.get(modulePath);
String fileNameNoPath = path.getFileName().toString();
String fileNameNoExtension = fileNameNoPath;
int extIdx = 0;
if ((extIdx = fileNameNoPath.lastIndexOf(".")) != -1) {
    fileNameNoExtension = fileNameNoPath.substring(0, extIdx + 1);
return fileNameNoExtension;
...
StringgetFilenameWithoutExtension(Path file)
Gets the filename without the extension
return getFilenameWithoutExtension(file.getFileName().toString());