Delete all files in directory (but not directory) - one liner solution

前端 未结 11 1367
不思量自难忘°
不思量自难忘° 2020-12-12 11:38

I want to delete all files inside ABC directory.

When I tried with FileUtils.deleteDirectory(new File(\"C:/test/ABC/\")); it also deletes folder ABC.

11条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 11:45

    import org.apache.commons.io.FileUtils;
    
    FileUtils.cleanDirectory(directory); 
    

    There is this method available in the same file. This will also recursively deletes all sub-folders and files under them.

    Docs: org.apache.commons.io.FileUtils.cleanDirectory

提交回复
热议问题