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

StringgetFileNameWithoutExt(final Path file)
Returns the file name of the specified file without its extension.
final String fileName = file.getFileName().toString();
final int dotIdx = fileName.lastIndexOf('.');
return dotIdx > 0 ? fileName.substring(0, dotIdx) : fileName;
PathgetFilePath(String dirName)
get File Path
return Paths.get(System.getProperty("user.dir"), "t", dirName);
StringgetFilePathName(Path filePath)
get File Path Name
return fixFilePathName(filePath.toString());
ListgetFilePathsInFolder(String sensorName)
get File Paths In Folder
List<String> pathList = new ArrayList<String>();
try (Stream<Path> paths = Files.walk(Paths.get("../../ase_data/atc-rawdata-1/" + sensorName))) {
    paths.forEach(filePath -> {
        if (Files.isRegularFile(filePath)) {
            pathList.add(filePath.toString());
    });
    Collections.sort(pathList);
...
voidgetFilesFromDirectory(Path directory, List filenames)
get Files From Directory
try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory)) {
    for (Path file : stream) {
        if (file.getFileName().toString().endsWith("/")) {
            getFilesFromDirectory(file, filenames);
        } else {
            filenames.add(directory.toString() + file.getFileName() + "");
} catch (IOException | DirectoryIteratorException x) {
    System.err.println(x);
StringgetFormattedDisplayName(String fileDisplayName, Path path, String baseDir)
get Formatted Display Name
StringBuilder builder = new StringBuilder();
builder.append(fileDisplayName);
String suffix = path.toString().replace(baseDir.substring(0, baseDir.length() - 1), "")
        .replace(File.separator, "|");
if (!suffix.startsWith("|")) {
    builder.append('|');
    builder.append(suffix);
} else {
...
StringgetFullFileName(Path path)
get Full File Name
String fileNameWithExt = path.getName(path.getNameCount() - 1).toString();
return fileNameWithExt;
PathgetFullPath(String basePath, String fileName)
get Full Path
return Paths.get(Paths.get(basePath, fileName).toString().replaceAll("~", System.getProperty("user.home")))
        .toAbsolutePath();
PathgetIndexPath(String rootDirectory, String basename)
get Index Path
return Paths.get(rootDirectory, basename + INDEX_FILE_EXT);
PathgetJarContainingClass(String path, String className)
get Jar Containing Class
File[] files = new File(path).listFiles(new FileFilter() {
    @Override
    public boolean accept(File pathname) {
        return pathname.isDirectory() || pathname.getName().endsWith(".jar");
});
for (File file : files) {
    Path pathFound = null;
...