tags:

views:

293

answers:

1

Do I have this right ...

To manipulate files on disk (create, copy, rename etc.) you use NSFileManager

To manipulate file contents (open, read, close etc.) you use NSFileHandle

I just want to make sure I am understanding this right.

EDIT_001

Thanks, thats what I figured Joshua, so I am assuming that by using the example below, open and close are both handled automatically by the implementation.

fileContents = [NSString stringWithContentsOfFile:fileOnDisk
                         encoding:NSMacOSRomanStringEncoding 
                         error:&fileError];

gary

+2  A: 

More or less, yes. From the docs:

NSFileHandle objects provide an object-oriented wrapper for accessing open files or communications channels.

... though NSFileHandle isn't necessary to read/write files. You can write an NSString to / read from a file with one line of code and no handle. Depends on what you want to do.

Joshua Nozzi
In answer to your edit, yes, all direct file handling concerns are abstracted away by -stringWithContentsOfFile:encoding:error:
Joshua Nozzi
You need only be concerned with whether the encoding is correct and whether the method fails (returns nil) and has produced an associated error.
Joshua Nozzi