Page 674 - Introduction to Programming with Java: A Problem Solving Approach
P. 674

                640
Chapter 15 Files
9. 10.
[after §15.7] In a binary file, carriage-return and new-line characters have no special function in reading or writing operations—they are just like any other characters. (T / F).
[after §15.8] Grocery Store Inventory:
Enhance the grocery-store Inventory program created in a Chapter 13 project by providing a FileHandler class that contains write and read methods to write an object to a file in the local directory or read an object from a file in the local directory. Complete the following skeleton by providing the needed code fragments. You don’t actually need the Chapter 13 grocery store Inventory program to do this exercise. You can test this new class with any appropriately instantiated object. The class that defines that object must, however, include a certain special feature. How would you modify the Inventory class to incorporate that special feature?
/*************************************************************
*
FileHandler.java
Dean & Dean
This stores and retrieves an object.
*************************************************************/
*
*
*
import java.util.*;
import java.io.*;
public class FileHandler
{
        Apago PDF Enhancer
public static void write(Object object, String filename)
{
}
// end write
ObjectOutputStream fileOut;
try
{
<provide code fragment here> catch (IOException e)
}
{
}
System.out.println(e.getMessage());
//**********************************************************
public static Object read(String filename)
{
ObjectInputStream fileIn;
Object object;
try
{
}
<provide code fragment here>


























































   672   673   674   675   676