Open and close are very expensive operations. You can improve performance by opening and closing files only as often as necessary. You can use a class to encapsulate I/O operations such as opening the files once, and not closing the file until the end of the program.
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.