Java Reference
In-Depth Information
Section 19.6
*19.5
( Store objects and arrays in a file ) Write a program that stores an array of the
five int values 1 , 2 , 3 , 4 and 5 , a Date object for the current time, and the
double value 5.5 into the file named Exercise19_05.dat .
*19.6
( Store Loan objects ) The Loan class in Listing 10.2 does not implement
Serializable . Rewrite the Loan class to implement Serializable . Write
a program that creates five Loan objects and stores them in a file named
Exercise19_06.dat .
*19.7
( Restore objects from a file ) Suppose a file named Exercise19_07.dat has
been created using the ObjectOutputStream . The file contains Loan
objects. The Loan class in Listing 10.2 does not implement Serializable .
Rewrite the Loan class to implement Serializable . Write a program that
reads the Loan objects from the file and computes the total loan amount.
Suppose you don't know how many Loan objects are in the file. Use
EOFException to end the loop.
Section 19.7
*19.8
( Update count ) Suppose you want to track how many times a program has
been executed. You can store an int to count the file. Increase the count by 1
each time this program is executed. Let the program be Exercise19_08 and
store the count in Exercise19_08.dat .
***19.9
( Address book ) Supplement VI.B has a case study of using random-access
files for creating and manipulating an address book. Modify the case study by
adding an Update button, as shown in Figure 19.19, to enable the user to mod-
ify the address that is being displayed.
F IGURE 19.19
The application can store, retrieve, and update addresses from a file.
Comprehensive
*19.10
( Split files ) Suppose you want to back up a huge file (e.g., a 10-GB AVI file) to
a CD-R. You can achieve it by splitting the file into smaller pieces and backing
up these pieces separately. Write a utility program that splits a large file into
smaller ones using the following command:
VideoNote
Split a large file
java Exercise19_10 SourceFile numberOfPieces
The command creates the files SourceFile.1 , SourceFile.2 , . . . , SourceFile.n ,
where n is numberOfPieces and the output files are about the same size.
**19.11
( Split files GUI ) Rewrite Exercise 19.10 with a GUI, as shown in Figure 19.20a.
*19.12
( Combine files ) Write a utility program that combines the files together into a
new file using the following command:
java Exercise19_12 SourceFile1 . . . SourceFilen TargetFile
The command combines SourceFile1, . . . , and SourceFilen
into
TargetFile.
Search WWH ::




Custom Search