在 Java/Unix 中,我知道您無法洗掉其中包含某些內容的檔案夾,并且我可以在沒有遞回的情況下執行此操作,但是這個簡單的解決方案很棒,但我只是看不到洗掉實際檔案的位置/時間?通過使用 delete() 函式。我在最后使用實際檔案夾上的 delete() 清楚地看到它,但我看不到它是如何的,或者它何時在檔案上呼叫 delete() 它只是獲取它們,當我覺得它應該呼叫 delete( ) 它進行遞回呼叫???
我知道這是我想念的簡單的東西,但它讓我發瘋,我在哪里可以找到答案,任何幫助將不勝感激。
boolean deleteDirectory(File directoryToBeDeleted) {
File[] allContents = directoryToBeDeleted.listFiles();
if (allContents != null) {
for (File file : allContents) {
deleteDirectory(file);
}
}
return directoryToBeDeleted.delete();
}
uj5u.com熱心網友回復:
directoryToBeDeleted并不總是一個目錄。如果allContents == nullthendirectoryToBeDeleted是檔案,而不是目錄,.listFiles()則回傳 null 如果型別的物件File是檔案而不是檔案夾。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/515760.html
標籤:爪哇递归目录io
