Java Reference
In-Depth Information
΢΢ Exercise P11.3. Write a program CopyFile that copies one file to
another. The file names are specified on the command line. For example,
java CopyFile report.txt report.sav
΢΢ Exercise P11.4. Write a program that concatenates the contents of several
files into one file. For example,
java CatFiles chapter1.txt chapter2.txt
chapter3.txt book.txt
makes a long file, book.txt , that contains the contents of the files
chapter1.txt , chapter2.txt , and chapter3.txt . The output
file is always the last file specified on the command line.
΢΢ Exercise P11.5. Write a program Find that searches all files specified on
the command line and prints out all lines containing a keyword. For
example, if you call
java Find ring report.txt address.txt
Homework.java
then the program might print
report.txt: has broken up an international ring
of DVD bootleggers that
address.txt: Kris Kringle, North Pole
address.txt: Homer Simpson, Springfield
Homework.java: String filename;
The keyword is always the first command line argument.
΢΢ Exercise P11.6. Write a program that checks the spelling of all words in a
file. It should read each word of a file and check whether it is contained in
a word list. A word list is available on most UNIX systems in the file
/usr/dict/words . (If you don't have access to a UNIX system, your
instructor should be able to get you a copy.) The program should print out
all words that it cannot find in the word list.
΢΢ Exercise P11.7. Write a program that replaces each line of a file with its
reverse. For example, if you run
Search WWH ::




Custom Search