Basic File Operations: NSFileHandle

The methods provided by NSFileHandle enable you to work more closely with files. At the beginning of this chapter, we listed some of the things you can do with these methods.

In general, follow these three steps when working with a file:

1. Open the file and obtain an NSFileHandle object to reference the file in subsequent I/O operations.

2. Perform your I/O operations on the open file.

3. Close the file.

Table 16.7 summarizes some commonly used NSFileHandle methods. In this table fh is an NSFileHandle object, data is an NSData object, path is an NSString object, and offset is an unsigned long long.

Table 16.7. Common NSFileHandle Methods

Not shown here are methods for obtaining NSFileHandles for standard ...

Get Programming in Objective-C, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.