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

voidaddNonEmptyLinesFromFile(final ArrayList result, final String path)
add Non Empty Lines From File
final List<String> lines = Files.readAllLines(Paths.get(path), StandardCharsets.UTF_8);
lines.stream().filter(s -> s.length() > 0).forEach(result::add);
PathMatcheranyPathMatcher(final ImmutableList pathMatchers)
A PathMatcher that returns true if any of the delegate pathMatchers returns true.
return new PathMatcher() {
    @Override
    public boolean matches(Path path) {
        for (PathMatcher pathMatcher : pathMatchers) {
            if (pathMatcher.matches(path)) {
                return true;
        return false;
    @Override
    public String toString() {
        return "anyOf[" + Joiner.on(", ").join(pathMatchers) + "]";
};
voidarchive(Path archive, List targetFiles)
Archives a list of target files into a ZIP archive
byte[] buffer = new byte[bufferSize];
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(archive.toFile()))) {
    for (Path file : targetFiles) {
        ZipEntry ze = new ZipEntry(file.getFileName().toString());
        zos.putNextEntry(ze);
        try (FileInputStream in = new FileInputStream(file.toFile())) {
            int len;
            while ((len = in.read(buffer)) > 0) {
...
ListasFileList(Object... paths)
as File List
List<File> files = new ArrayList<File>(paths.length);
for (Object it : paths) {
    if (it instanceof CharSequence) {
        files.add(new File(it.toString()));
    } else if (it instanceof File) {
        files.add((File) it);
    } else if (it instanceof Path) {
        files.add(((Path) it).toFile());
...
ListasPathsList(final File[] files)
Convert an array of java.io.File to a List of java.nio.file.Path
return Optional.ofNullable(files)
        .map(fs -> Arrays.stream(fs).map(File::toPath).collect(Collectors.toList()))
        .orElse(Collections.EMPTY_LIST);
booleancompileTreeWithErrors(JavaCompiler compiler, List options, File targetFolder, DiagnosticListener diagnosticListener, boolean addProcessorsToClasspath)
compile Tree With Errors
return compileTreeWithErrors(compiler, options, targetFolder, diagnosticListener, false,
        addProcessorsToClasspath);
SetdeepListChildren(Path directory)
deep List Children
return deepListChildren(directory, DEFAULT_GLOB);
ArrayListfileListDeep(Path dir)
file List Deep
try {
    if (Files.exists(dir)) {
        Stream<Path> ds = Files.walk(dir);
        ArrayList<Path> dirList = new ArrayList<Path>();
        Iterator<Path> it = ds.iterator();
        while (it.hasNext()) {
            Path tp = it.next();
            if (!Files.isDirectory(tp)) {
...
PathfindExpectedResultForTestcase(final Path testcase, final LinkedList expectedResults)
find Expected Result For Testcase
final String fileName = getFileName(testcase);
final Iterator<Path> it = expectedResults.iterator();
while (it.hasNext()) {
    final Path result = it.next();
    if (fileName.equalsIgnoreCase(getFileName(result))) {
        it.remove();
        return result;
return null;
ClassLoadergetClassLoaderFromPaths(ArrayList paths)
get Class Loader From Paths
ArrayList<URL> urls = new ArrayList<URL>();
for (Path p : paths) {
    try {
        URL url = p.toUri().toURL();
        urls.add(url);
    } catch (MalformedURLException e) {
        e.printStackTrace();
URL[] urlsArray = new URL[urls.size()];
urlsArray = urls.toArray(urlsArray); 
ClassLoader cl = new URLClassLoader(urlsArray);
return cl;