Commons-IO contains utility classes, stream implementations, file filters, and endian classes. IO has recently been promoted from the commons sandbox, however there remains no formal release at present.

For a more detailed descriptions, take a look at the JavaDocs.

org.apache.commons.io.CopyUtils contains a comprehensive set of static methods for copying from String, byte[], InputStream, Reader to OutputStream, Writer.

org.apache.commons.io.IOUtils contains additional IO-related tools for safely closing streams and creating Strings and byte arrays from streams and Readers.

As an example, consider the task of reading bytes from a URL, and printing them. This would typically done like this:

InputStream in = new URL( "http://jakarta.apache.org" ).openStream(); try { InputStreamReader inR = new InputStreamReader( in ); BufferedReader buf = new BufferedReader( inR ); String line; while ( ( line = buf.readLine() ) != null ) { System.out.println( line ); } } finally { in.close(); }

With the IOUtils class, that could be done with:

InputStream in = new URL( "http://jakarta.apache.org" ).openStream(); try { System.out.println( IOUtils.toString( in ) ); } finally { IOUtils.closeQuietly(in); }

In certain application domains, such IO operations are common, and this class can save a great deal of time. And you can rely on well-tested code. For utility code such as this, flexibility and speed are of primary importance.

The org.apache.commons.io.FileUtils class contains methods for retrieving different components of a file path (directory name, file base name, file extension), methods for copying files to other files and directories, and methods for querying, deleting and cleaning directories. For more information, see the class description.

The org.apache.commons.io.filefilter package defines an interface (IOFileFilter) that combines both java.io.FileFilter and java.io.FilenameFilter. Besides that the package offers a series of ready-to-use implementations of the IOFileFilter interface including implementation that allow you to combine other such filters. These filter can be used to list files or in FileDialog, for example.

Different computer architectures adopt different conventions for byte ordering. In so-called "Little Endian" architectures (eg Intel), the low-order byte is stored in memory at the lowest address, and subsequent bytes at higher addresses. For "Big Endian" architectures (eg Motorola), the situation is reversed.

There are two classes in this package of relevance:

  • The org.apache.commons.io.EndianUtils class contains static methods for swapping the Endian-ness of Java primitives and streams.
  • The org.apache.commons.io.input.SwappedDataInputStream class is an implementation of the DataInput interface. With this, one can read data from files of non-native Endian-ness.

For more information, see http://www.cs.umass.edu/~verts/cs32/endian.html