开发者

Remove files using a unix-like pattern

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜