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();
}
精彩评论