69 816
Assignments Done
Successfully Done
In February 2019

Answer to Question #63986 in Java | JSP | JSF for hamod

Question #63986
write a java code segment that will return the number of files founds inside the directory "d:/windows" iff the named directory does indeed exists
Expert's answer
public class Main {

public static void main(String[] args) throws IOException {



public static int getFilesCount(Path dir) throws IOException {

int countFiles = 0;

if(Files.isDirectory(dir)) {

try(DirectoryStream<Path> files = Files.newDirectoryStream(dir)) {

for(Path file : files) {

if(Files.isRegularFile(file) || Files.isSymbolicLink(file)) {







throw new NotDirectoryException(dir + " is not directory");

return countFiles;



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions