close

一. 題目

Given the code fragment:

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.

二. 題解

listFiles()找出 dirName的所有檔案,
第4行迴圈取得 listOfFiles的每一個檔案,
若檔案為資料夾,則再次呼叫 recDelete()方法,參數帶入該檔案的絕對路徑,
不是資料夾且結尾有".class"字尾,則刪除該檔案。

三. 參考

[OCPJP]遞迴刪除檔案

 

arrow
arrow
    文章標籤
    Java OCP 1Z0-809
    全站熱搜

    書童 發表在 痞客邦 留言(0) 人氣()