Java Utililty Methods Path File List nio

List of utility methods to do Path File List nio

Description

The list of methods to do Path File List nio are organized into topic(s).

Method

voidloadTrainingData(Path path, List input, List output, int outputCount)
load Training Data
List<String> lines = Files.readAllLines(path);
Collections.shuffle(lines, new Random(System.nanoTime()));
for (int i = 0; i < lines.size(); i++) {
    String[] pieces = lines.get(i).split("\\s");
    float[] tmpInput = new float[pieces.length - outputCount];
    float[] tmpOutput = new float[outputCount];
    for (int k = 0; k < pieces.length - outputCount; k++) {
        tmpInput[k] = Float.parseFloat(pieces[k]);
...
voidmergeFiles(List files, Path mergedFile)
merge Files
try (FileChannel out = FileChannel.open(mergedFile, StandardOpenOption.APPEND, StandardOpenOption.WRITE)) {
    for (Path path : files) {
        try (FileChannel in = FileChannel.open(path, StandardOpenOption.READ)) {
            for (long p = 0, l = in.size(); p < l;)
                p += in.transferTo(p, l - p, out);
} catch (IOException e) {
...
voidmergeInto(List parts, OutputStream out)
Merge the given part files in order into an output stream.
for (final Path part : parts) {
    Files.copy(part, out);
    Files.delete(part);
PredicatepathContainsAny(List strings)
path Contains Any
return path -> {
    boolean included = strings.stream()
            .anyMatch(wildcardMatcher -> path.toString().contains(wildcardMatcher));
    return included;
};
SetrecursiveListFiles(Path file)
recursive List Files
Set<Path> files = new HashSet<Path>();
files.add(file);
if (file.toFile().isDirectory()) {
    for (File child : file.toFile().listFiles()) {
        files.addAll(recursiveListFiles(child.toPath()));
return files;
...
voidrecusivelyCollectFileListing(ArrayList rc, Path base, Path directory)
recusively Collect File Listing
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory)) {
    for (Path path : directoryStream) {
        if (Files.isDirectory(path)) {
            recusivelyCollectFileListing(rc, base, path);
        } else {
            rc.add(base.relativize(path).toString());
voidregisterRecursive(final WatchService watcher, final List startingPaths)
Register the given directory, and all its sub-directories, with the WatchService.
for (Path start : startingPaths) {
    Files.walkFileTree(start, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
            register(watcher, dir);
            return FileVisitResult.CONTINUE;
    });
...
ListretrieveTokenFilesInDirImportableFrom(Path dir, List excludedTokenFiles)
retrieve Token Files In Dir Importable From
assert dir != null;
List<String> answer = new ArrayList<>();
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**/*.tokens");
try (DirectoryStream<Path> filePathStream = Files.newDirectoryStream(dir);) {
    Iterator<Path> iterator = filePathStream.iterator();
    while (iterator.hasNext()) {
        Path path = iterator.next();
        if (matcher.matches(path)) {
...
StringtoCliString(Path agentPath, String param)
to Cli String
if (param != null && !param.isEmpty()) {
    return "-javaagent:" + agentPath.toString() + "=" + param;
} else {
    return "-javaagent:" + agentPath.toString();
voidtoFile(Path file, String list)
to File
FileOutputStream fos = null;
try {
    fos = new FileOutputStream(file.toString());
    fos.write(list.getBytes());
    fos.flush();
} finally {
    if (fos != null)
        fos.close();
...