开发者

Remove files using a unix-like pattern

开发者 https://www.devze.com 2022-12-13 18:15 出处:网络
I would like to implem开发者_如何学JAVAent something equivalent to the unix command \'rm foo*\' using Java. Obviously, I want it to be multi platform. I know that this can be done using the FilenameFi

I would like to implem开发者_如何学JAVAent something equivalent to the unix command 'rm foo*' using Java. Obviously, I want it to be multi platform. I know that this can be done using the FilenameFilter class and File.delete() method, but I was wondering if I can perform this simple operation in a less verbose way.

Thanks in advance.


Look in commons-io for org.apache.commons.io.filefilter.WildcardFileFilter.

for (File file : new File(".").listFiles(new WildcardFilter("foo*"))) {
  file.delete();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号