Print Directory and File Contents Using JDK8

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;

import org.testng.annotations.Test;

public class FilesTest {
@Test
public void listFiles() throws IOException, URISyntaxException
{
Files.walk(Paths.get(“C://Users//asharda//core”))
.filter(Files::isRegularFile)
.forEach(System.out::println);
Files.list(Paths.get(“C://Users//asharda//core”)).forEach(System.out::println);
Files.lines(Paths.get(“C://Users//asharda//core//Base.java”)).forEach(System.out::println);
}
}

 

In this example instead of directory specified replace it with your working directory and file name.

Advertisements

About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Java. Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s