10.1. Obtaining Commons IO

Problem

You need to use Jakarta Commons IO.

Solution

You must download the latest version of Commons IO, and place the Commons IO JAR in your project’s classpath. Following the steps outlined in Recipe 1.1, download Commons IO 1.0 instead of Commons Lang.

Discussion

Commons IO contains a few utilities for simplifying a number of common I/O tasks. CopyUtils and IOUtils in the org.apache.commons.io package provide a suite of static utility methods for working with streams and readers. org.apache.commons.io.FileUtils provides static utility methods to help with common File operations, such as touching a file, recursive deletion of directories, and reading files. The org.apache.commons.io.filefilter package contains implementations of FilenameFilter, such as SuffixFileFilter, which accepts files with a specified name suffix.

If you have a Maven project, which needs to use Commons IO, add a dependency on Commons IO 1.0 with the following section in project.xml:

<dependencies>
  <dependency>
    <id>commons-io</id>
    <version>1.0</version>
  </dependency>
  ....other dependencies...
</dependencies>

See Also

For more information about the Commons IO project, see the project page at http://jakarta.apache.org/commons/io. If you have questions about using Commons IO, please feel free to join the http://commons-user@jakarta.apache.org mailing list. Instructions for joining the user mailing list can be found in Recipe 1.2.

Get Jakarta Commons Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.