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

StringgetLatestUpgradeScriptName(Path upgradeScriptsDir)
get Latest Upgrade Script Name
List<String> fileNames = new ArrayList<>();
DirectoryStream.Filter<Path> fileFilter = new DirectoryStream.Filter<Path>() {
    public boolean accept(Path file) throws IOException {
        return !Files.isDirectory(file);
};
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(upgradeScriptsDir, fileFilter)) {
    for (Path path : directoryStream) {
...
StringgetLocalFilePath(String localDirectory, String filename)
get Local File Path
if (localDirectory != null) {
    return getPath(localDirectory, filename);
return filename;
StringgetManifestProperty(Path pathToJar, String propertyName)
get Manifest Property
File file = pathToJar.toFile();
try (JarFile jar = new JarFile(file)) {
    Manifest manifest = jar.getManifest();
    Attributes attributes = manifest.getMainAttributes();
    return attributes.getValue("Bundle-Version");
StringgetName(Path file)
get Name
Path name = file.getFileName();
return name == null ? "" : name.toString();
StringgetName(Path path)
get Name
return getFileName(path);
StringgetName(Path path)
get Name
return Optional.ofNullable(path.getFileName()).map(Path::toString)
        .orElseThrow(() -> new IllegalStateException(path.toString()));
StringgetName(Path path)
Returns the name of the file or directory from the given path.
return path.getFileName().toString();
StringgetName(String path)

Get the name and extension of a file

return getName(Paths.get(path));
StringgetNamePart(Path file)
get Name Part
String s = file.getFileName().toString();
return getNamePart(s);
StringgetNameWithoutSuffix(Path path)
get Name Without Suffix
String name = path.getFileName().toString();
int index = name.lastIndexOf('.');
if (index == -1) {
    return name;
return name.substring(0, index);