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
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!
Learn more about our help with Assignments:
JavaJSPJSF