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

PathgetPathByFormat(String nameBeforeDot, String nameAfterDot, Path parent, int i, String date)
get Path By Format
Path renamed;
String fileName = String.format(FILE_NAME_FORMAT, nameBeforeDot, date, i, nameAfterDot);
if (parent == null) {
    renamed = Paths.get(fileName);
} else {
    renamed = parent.resolve(fileName);
return renamed;
...
StringgetPathCleanName(Path object)
get Path Clean Name
return object.getFileName().toString().replaceAll("\\..*", "");
PathgetPathInTmpDir(String fileName)
get Path In Tmp Dir
return Paths.get(TMP_DIR + "/" + fileName);
StringGetPathName(String path)
Get Path Name
return Path2UnixStr(Paths.get(path).getFileName());
PathgetPathOfClass(Class cls, String filename)
get Path Of Class
URL uri = cls.getResource(filename);
return uri == null ? null : Paths.get(uri.getFile());
PathgetPathProperty(Properties props, String propName)
Gets a property (in Path) from config.properties
String strValue;
Path path;
try {
    strValue = getProperty(props, propName);
} catch (Exception e) {
    throw e;
try {
...
ListgetPaths(Path dir, String fileNames)
get Paths
List<Path> paths = new ArrayList<>();
DirectoryStream<Path> directories = Files.newDirectoryStream(dir);
for (Path path : directories) {
    if (!Files.isDirectory(path)) {
        continue;
    Path file = path.resolve(fileNames);
    if (!Files.exists(file)) {
...
StringgetPrefix(final Path file, final int filenameSuffixLength)
Get part of filename before given suffix
assert file != null;
final Path fileName = file.getFileName();
if (fileName == null) {
    throw new IllegalArgumentException("Invalid file (no filename, probably root?): " + file);
final String filename = fileName.toString();
return filename.substring(0, filename.length() - filenameSuffixLength);
PrintWritergetPrintWriter(String className, String flushPath)
get Print Writer
File root = new File(flushPath);
String path = root.getAbsolutePath() + File.separator + className + ".java";
File classFile = prepareFile(path);
try {
    return new PrintWriter(
            new OutputStreamWriter(new FileOutputStream(classFile), Charset.defaultCharset()));
} catch (Exception e) {
    e.printStackTrace();
...
ListgetProvenanceLogFiles(final String baseName, final Collection allProvenanceLogs)
get Provenance Log Files
final List<File> matchingFiles = new ArrayList<>();
final String searchString = baseName + ".";
for (final Path path : allProvenanceLogs) {
    if (path.toFile().getName().startsWith(searchString)) {
        final File file = path.toFile();
        if (file.exists()) {
            matchingFiles.add(file);
        } else {
...