A friend of mine just asked me how to write a Java code that will perform a search on a directory and all of its subdirectories (recursively) matching a given file suffix, for example, all JSP files. I remembered that I was doing a small project a few months ago that had to deal with this functionality. And, I also remembered that it was a simple thing to do.
So I went to the jakarta-commons site, looking for the commons-io component. After looking at the javadoc for the next few seconds, suddenly it's all there. The solution is all there. Just one line of code, and you're done.
Collection jspFiles = FileUtils.listFiles
(rootDirName, new String[] { "jsp" }, true);
I can't keep myself from the amusement caused by the great work that open source people have done. This is yet another prove that a lot of browsing could actually prove beneficial.. :D
It's nice to see the benefits of open source components. I'd certainly went and looked for jakarta-commons next time I'd ever need anything "common".. :D
Kudos to the great guys everywhere in the open source world.. :D
Further Reading:
Jakarta Commons Cookbook
Pro Jakarta Commons
Apache Jakarta Commons
Applied Software Engineering using Apache Jakarta Commons
No comments:
Post a Comment