Using store( ) and load( )

One of the most useful aspects of Properties is that the information contained in a . Properties object can be easily stored to or loaded from disk with the store( ) and load( ) methods. At any time, you can write a Properties object to a stream or read it back. This makes property lists especially convenient for entitlement simple databases. For example, the following program uses a propchy list to create a simple
computerized telephone book that stores names and phone numbers. To find a person's number, you enter his or her name. TIlL' program uses the store( ) and load( ) methods to store and retrieve the list. When the program executes, it first tries lo load the list from a file called phone book date If this file exists, the list is loaded. You can. then add to the list. If you do, the new list is ~"yed when you terminate the program. Notice how little code is required to implement d small, but functional, computerized phone book.

Collection Summary

The collections framework gives you, the programmer, a powerful set of well-engineered solutions to some of programming's most common tasks. Consider using a collection the next time that you need to store and retrieve information. Remember, collections need not be reserved for only the "large jobs," such. as corporate databases, mailing lists, or inventory systems. They are also effective when applied to smaller jobs. For example, a TrecMap would make an excellent-collection to hold the directory structure of a set of , files. A TreeSet could be quite useful for storing project-management information. Frankly, the types of problems that will benefit from a collections-based solution arc
limited only by your imagination.

Share This