Before a file is accessed it must be opened using the open() statement, and after the last access the file is closed using close(). The open() routine takes two parameters. The first is a string that gives the name of the file to open. The second is a string that specifies the mode of access: "r" for read, "w" for write, and "a" for append. If successful, open() returns a file variable that can be used to access the file as described in the next subsection. If unsuccessful, open() returns 0.
The following example shows how a file is opened for reading.
var f : file; . . . f := open ("input", "r"); -- open file for readingThe close() procedure takes a file parameter that was obtained from open().