63 050
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #63024 in Java | JSP | JSF for jonney

Question #63024
write a java code segment that will return the number of file found inside the directory "d:/windows" iff the named directory does indeed exists
Expert's answer

public class FileCounter {

/**
* Returns the number of files found inside the directory "d:/windows" if
* the named directory does indeed exists or -1 otherwise
* @return
*/
public static int countFiles() {
java.io.File winDir = new java.io.File("d:/windows");
if (winDir.exists()) return winDir.listFiles().length;
else return -1;
}

/**
* Driver method. Prints out the number of files in d:/windows.
* @param args
*/
public static void main(String[] args) {
int count = countFiles();
if (count > -1) System.out.println("Number of files in d:/windows: " + count);
else System.out.println("No such directory exists");
}
}

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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions