Package org.apache.commons.io

Utility code for IO operations.

See:
          Description

Class Summary
CopyUtils This class provides static utility methods for buffered copying between sources (InputStream, Reader, String and byte[]) and destinations (OutputStream, Writer, String and byte[]).
EndianUtils Utility code for dealing with different endian systems.
FileCleaner Keeps track of files awaiting deletion, and deletes them when an associated marker object is reclaimed by the garbage collector.
FileUtils This class provides basic facilities for manipulating files and file paths.
HexDump Dumps data in hexadecimal format.
IOUtils General IO Stream manipulation.
 

Package org.apache.commons.io Description

Utility code for IO operations.
NOTE: Some classes are not yet included in this description

[Introduction] [IO Utilities] [File Utilities] [Endian Utilities]

Introduction

The org.apache.commons.io package contains utility code for file- and stream-based IO operation.

The org.apache.commons.io.IOUtils class

The IOUtils class contains a comprehensive set of static methods for copying from:

To:

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

import java.net.URL;
import java.io.*;

public class ManualCopy {
public static void main(String args[]) throws IOException {
InputStream in = new URL( "http://jakarta.apache.org" ).openStream();
InputStreamReader inR = new InputStreamReader( in ); BufferedReader buf = new BufferedReader( inR ); String line; while ( ( line = buf.readLine() ) != null ) { System.out.println( line ); } in.close(); } }

With the IOUtils class, that could be done with:

import java.net.URL;
import java.io.*;
import org.apache.commons.io.IOUtils;

public class IOUtilsCopy {
public static void main(String args[]) throws IOException {
InputStream in = new URL( "http://jakarta.apache.org" ).openStream();
System.out.println( IOUtils.toString( in ) ); in.close(); } }

In certain application domains, such IO operations are common, and this class can save a great deal of time.

For utility code such as this, flexibility and speed are of primary importance. In IOUtils, each kind of copy method has a variant which allows the buffer size to be set. For methods that convert bytes to chars, the encoding method may also be set.

The org.apache.commons.io.FileUtils class

The 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 deleting and cleaning directories. For more information, see the class description

The Endian classes

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:

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




Copyright © 2002-2005 The Apache Software Foundation. All Rights Reserved.