List of utility methods to do Path File Name nio
String | getFileNameWithoutExt(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; |
Path | getFilePath(String dirName) get File Path return Paths.get(System.getProperty("user.dir"), "t", dirName); |
String | getFilePathName(Path filePath) get File Path Name return fixFilePathName(filePath.toString());
|
List | getFilePathsInFolder(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); ... |
void | getFilesFromDirectory(Path directory, List 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); |
String | getFormattedDisplayName(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 { ... |
String | getFullFileName(Path path) get Full File Name String fileNameWithExt = path.getName(path.getNameCount() - 1).toString();
return fileNameWithExt;
|
Path | getFullPath(String basePath, String fileName) get Full Path return Paths.get(Paths.get(basePath, fileName).toString().replaceAll("~", System.getProperty("user.home"))) .toAbsolutePath(); |
Path | getIndexPath(String rootDirectory, String basename) get Index Path return Paths.get(rootDirectory, basename + INDEX_FILE_EXT);
|
Path | getJarContainingClass(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; ... |