Java better way to delete file if exists

后端 未结 10 654
慢半拍i
慢半拍i 2020-12-24 10:21

We need to call file.exists() before file.delete() before we can delete a file E.g.

 File file = ...;
 if (file.exists()){
     fil         


        
10条回答
  •  孤城傲影
    2020-12-24 10:49

    Use the below statement to delete any files:

    FileUtils.forceDelete(FilePath);
    

    Note: Use exception handling codes if you want to use.

提交回复
热议问题