fuzzygoat
fuzzygoat

Reputation: 26223

NSFileManager & NSFileHandle?

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

Upvotes: 2

Views: 2465

Answers (2)

loghound
loghound

Reputation: 686

I believe, for the most part, that NSFileHandle is a wrapper around file descriptors -- good for 'relatively' low level reading or writing.

If you are just pushing the contents of a string or NSData to or from a file the associated methods on those classes are hard to beat.

Upvotes: 0

Joshua Nozzi
Joshua Nozzi

Reputation: 61228

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.

Upvotes: 3

Related Questions