Java Programming 10-Minute Solutions
Chapter One
File I/O
SOLUTION 1 Copying and Deleting Directories and Files
SOLUTION 2 Reading and Writing JAR/ZIP Files
SOLUTION 3 Java Object Persistence with Serialization
SOLUTION 4 Using Random Access File I/O
SOLUTION 5 Writing Text Filters
SOLUTION 1
Copying and Deleting Directories and Files
PROBLEM
Your Java application needs to
be able to copy and delete individual files
and entire directories. You also want the
option of copying and deleting nested file
directories. You need to get lists of files
in directories.
SOLUTION
I will present a Java utility class
FileUtils that you can use in your Java programs
to copy and delete files and nested
directories and also get directory listings.
One of the advantages of the Java platform is that once you know a technique like opening and
reading files, that technique works on all computing platforms that support Java. In this solution
you will build on the inherent portability of Java with a Java class library for general file
manipulations that will solve most of your file handling problems on any platform. We will
start by discussing the API ... read full excerpt from Java Programming 10-Minute Solutions ebook