Chapter 10. I/O and Networking
Introduction
If you’ve ever had to copy a File
or copy the contents of an InputStream to an
OutputStream, you’ve probably
wondered why Java goes out of its way to make things difficult. Java
I/O is not a terribly complex subject, but it does have a knack for
turning simpler tasks into complex nests of heavily wrapped
Readers and streams. Jakarta Commons IO fills a
few gaps in Java’s I/O and networking capabilities
by providing utilities and methods to copy streams, copy files, touch
files, recursively delete directories, and safely close
Readers and streams. If you are working with
Reader, Writer,
InputStream, or OutputStream,
you should take a look at IOUtils and
CopyUtils; they may save you a few lines of
tedious code.
Commons IO also provides a set of simple
FilenameFilter implementations, which can be used
to selectively list files or directories. In addition to Commons
IO’s FilenameFilter
implementations, Jakarta ORO’s
GlobFilenameFilter and
Perl5FilenameFilter are presented to introduce you
to more complex filters involving expressions. ORO is a subproject of
Jakarta that provides support for Perl 5 regular expressions and glob
expressions. A glob expression is commonly used when listing files in
a directory; for example, the expression, *.xml,
is a glob expression that matches every file that ends in
.xml. While Java 1.4 provides support for regular expressions, there are subtle differences between the regular expression syntax supported by Java ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access