Java – Recursive Folder reading


package com.pwn.nio;

import java.nio.file.FileVisitOption;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.EnumSet;

public class NIORecrusiveFolderReading {
	public static void main(String args[]) {

		Path dirPath = new File("C://install").toPath();

		try {
					EnumSet.noneOf(FileVisitOption.class), 1,
					new SimpleFileVisitor() {
						public FileVisitResult preVisitDirectory(
								Path selectedPath,
								BasicFileAttributes attrs)
								throws IOException {
							System.out.println("d "
									+ selectedPath.toAbsolutePath());
							return FileVisitResult.CONTINUE;

						public FileVisitResult visitFile(
								Path selectedPath,
								BasicFileAttributes attrs)
								throws IOException {
							System.out.println("f "
									+ selectedPath.toAbsolutePath());
							return FileVisitResult.CONTINUE;
		} catch (IOException e) {


d C:\install
f C:\install\AnypointStudio
f C:\install\Apache Tomcat 8.0.27
f C:\install\apache-maven-3.5.2
f C:\install\eclipse
f C:\install\glassfish-4.1.1
f C:\install\instructions.txt
f C:\install\NetBeans 8.2
f C:\install\spring-tool-suite-3.9.1
f C:\install\sqldeveloper
f C:\install\user.xml
f C:\install\userDetail.xml
f C:\install\workspace

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s