Given the code fragment:

public void recDelete(String dirName) throws IOException {
    File[] listOfFiles = new File(dirName).listFiles();
    if (listOfFiles != null && listOfFiles.length > 0) {
        for (File aFile : listOfFiles) {
            if (aFile.isDirectory()) {
                recDelete(aFile.getAbsolutePath());
            } else if (aFile.getName().endsWith(".class")) {
                aFile.delete();
            }
        }
    }
}

Assume that Projects contains subdirectories that contain .class files and is passed as an argument to the recDelete() method when it is invoked.

What is the result?

A. The method deletes all the .class files in the Projects directory and its subdirectories.
B. The method deletes the .class files of the Projects directory only.
C. The method executes and does not make any changes to the Projects directory.
D. The method throws an IOException.

题解

程序第 16 行,会找出 dirName 这个目录下的所有文件(不包括子目录中的文件)。程序第 18 行的 for 循环,会走访所有文件。若文件为目录,则再用这个目录递归调用 recDelete 方法;若文件不是目录,且文件名是「.class」结尾的话,则删除之。

所以答案是选项 A。