2016-11-20 36 views

回答

0

File.delete()返回一個布爾值,告訴您文件是否已被正確刪除。
所以,你可以寫這樣的:

if(yourFile.delete()) { 
    //keep doing what you want. You are now sure file has been deleted ! 
} 

此外,寫一個新的文件之前,你可以檢查是否具有相同名稱的文件已經存在。

從Oracle文檔:

Returns: 
true if and only if the file or directory is successfully deleted; false otherwise 

Oracle source

Also there is a SO thread that might help you

+0

我不知道如果布爾表示該文件是不再顯示在文件系統中,或者如果它實際上可能是在稍後時間被刪除? –

+0

當返回true時,文件已被刪除。 – HelloSadness

相關問題