Tasks
Getting a File Handle
+ fileHandleForReadingAtPath:
+ fileHandleForReadingFromURL:error:
+ fileHandleForWritingAtPath:
+ fileHandleForWritingToURL:error:
+ fileHandleForUpdatingAtPath:
+ fileHandleForUpdatingURL:error:
+ fileHandleWithStandardError
+ fileHandleWithStandardInput
+ fileHandleWithStandardOutput
+ fileHandleWithNullDevice
Creating a File Handle
Getting a File Descriptor
Reading from a File Handle
Writing to a File Handle
Reading and Writing Using Blocks
-
readabilityHandler
property -
writeabilityHandler
property
Communicating Asynchronously
– acceptConnectionInBackgroundAndNotify
– acceptConnectionInBackgroundAndNotifyForModes:
– readInBackgroundAndNotify
– readInBackgroundAndNotifyForModes:
– readToEndOfFileInBackgroundAndNotify
– readToEndOfFileInBackgroundAndNotifyForModes:
– waitForDataInBackgroundAndNotify
– waitForDataInBackgroundAndNotifyForModes:
Seeking Within a File
Operating on a File
Properties
readabilityHandler
The block to use for reading the contents of the file handle asynchronously.
Discussion
The default value of this property is nil
. Assigning a valid block object to this property creates a dispatch source for reading the contents of the file or socket. Your block is submitted to the file handle’s dispatch queue when there is data to read. When reading a file, your handler block is typically executed repeatedly until the entire contents of the file have been read. When reading data from a socket, your handler block is executed whenever there is data on the socket waiting to be read.
The block you provide must accept a single parameter that is the current file handle. The return type of your block should be void
.
To stop reading the file or socket, set the value of this property to nil
. Doing so cancels the dispatch source and cleans up the file handle’s structures appropriately.
Availability
- Available in OS X v10.7 and later.
Declared In
NSFileHandle.h
writeabilityHandler
The block to use for writing the contents of the file handle asynchronously.
Discussion
The default value of this property is nil
. Assigning a valid block object to this property creates a dispatch source for writing the contents of the file or socket. Your block is submitted to the file handle’s dispatch queue when there is room available to write more data. When writing a file, your handler block is typically executed repeatedly until the entire contents of the file have been written. When writing data to a socket, your handler block is executed whenever the socket is ready to accept more data.
The block you provide must accept a single parameter that is the current file handle. The return type of your block should be void
.
To stop writing data to the file or socket, set the value of this property to nil
. Doing so cancels the dispatch source and cleans up the file handle’s structures appropriately.
Availability
- Available in OS X v10.7 and later.
Declared In
NSFileHandle.h
Tasks
Creating a File Manager
Locating System Directories
Locating Application Group Container Directories
Discovering Directory Contents
– contentsOfDirectoryAtURL:includingPropertiesForKeys:options:error:
– contentsOfDirectoryAtPath:error:
– enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:
– enumeratorAtPath:
– mountedVolumeURLsIncludingResourceValuesForKeys:options:
– subpathsOfDirectoryAtPath:error:
– subpathsAtPath:
Creating and Deleting Items
– createDirectoryAtURL:withIntermediateDirectories:attributes:error:
– createDirectoryAtPath:withIntermediateDirectories:attributes:error:
– createFileAtPath:contents:attributes:
– removeItemAtURL:error:
– removeItemAtPath:error:
– replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:
– trashItemAtURL:resultingItemURL:error:
Moving and Copying Items
– copyItemAtURL:toURL:error:
– copyItemAtPath:toPath:error:
– moveItemAtURL:toURL:error:
– moveItemAtPath:toPath:error:
Managing ICloud-Based Items
– ubiquityIdentityToken
– URLForUbiquityContainerIdentifier:
– isUbiquitousItemAtURL:
– setUbiquitous:itemAtURL:destinationURL:error:
– startDownloadingUbiquitousItemAtURL:error:
– evictUbiquitousItemAtURL:error:
– URLForPublishingUbiquitousItemAtURL:expirationDate:error:
Creating Symbolic and Hard Links
– createSymbolicLinkAtURL:withDestinationURL:error:
– createSymbolicLinkAtPath:withDestinationPath:error:
– linkItemAtURL:toURL:error:
– linkItemAtPath:toPath:error:
– destinationOfSymbolicLinkAtPath:error:
Determining Access to Files
– fileExistsAtPath:
– fileExistsAtPath:isDirectory:
– isReadableFileAtPath:
– isWritableFileAtPath:
– isExecutableFileAtPath:
– isDeletableFileAtPath:
Getting and Setting Attributes
– componentsToDisplayForPath:
– displayNameAtPath:
– attributesOfItemAtPath:error:
– attributesOfFileSystemForPath:error:
– setAttributes:ofItemAtPath:error:
Getting and Comparing File Contents
Converting File Paths to Strings
Managing the Delegate
Managing the Current Directory
Deprecated Methods
– changeFileAttributes:atPath:
Deprecated in OS X v10.5– copyPath:toPath:handler:
Deprecated in OS X v10.5– createDirectoryAtPath:attributes:
Deprecated in OS X v10.5– createSymbolicLinkAtPath:pathContent:
Deprecated in OS X v10.5– directoryContentsAtPath:
Deprecated in OS X v10.5– fileAttributesAtPath:traverseLink:
Deprecated in OS X v10.5– fileSystemAttributesAtPath:
Deprecated in OS X v10.5– linkPath:toPath:handler:
Deprecated in OS X v10.5– movePath:toPath:handler:
Deprecated in OS X v10.5– pathContentOfSymbolicLinkAtPath:
Deprecated in OS X v10.5– removeFileAtPath:handler:
Deprecated in OS X v10.5– fileManager:shouldProceedAfterError:
delegate method Deprecated in OS X v10.5– fileManager:willProcessPath:
delegate method Deprecated in OS X v10.5