NSFileHandle
NSFileHandle 表示一个文件句柄,可用于读取/写入数据,或访问标准输入/输出/错误。
类成员 (Class members)
Section titled “类成员 (Class members)”fileHandleWithStandardInput
Section titled “fileHandleWithStandardInput”标准输入句柄。
static fileHandleWithStandardInput(): NSFileHandleReturn Value:
NSFileHandle: 标准输入句柄。
fileHandleWithStandardOutput
Section titled “fileHandleWithStandardOutput”标准输出句柄。
static fileHandleWithStandardOutput(): NSFileHandleReturn Value:
NSFileHandle: 标准输出句柄。
fileHandleWithStandardError
Section titled “fileHandleWithStandardError”标准错误句柄。
static fileHandleWithStandardError(): NSFileHandleReturn Value:
NSFileHandle: 标准错误句柄。
fileHandleWithNullDevice
Section titled “fileHandleWithNullDevice”空设备句柄。
static fileHandleWithNullDevice(): NSFileHandleReturn Value:
NSFileHandle: 空设备句柄。
fileHandleForReadingAtPath
Section titled “fileHandleForReadingAtPath”以只读方式打开文件。
static fileHandleForReadingAtPath(path: string): NSFileHandleParameters:
| Name | Type | Description |
|---|---|---|
path | string | 文件路径。 |
Return Value:
NSFileHandle: 句柄实例。
fileHandleForWritingAtPath
Section titled “fileHandleForWritingAtPath”以只写方式打开文件。
static fileHandleForWritingAtPath(path: string): NSFileHandleParameters:
| Name | Type | Description |
|---|---|---|
path | string | 文件路径。 |
Return Value:
NSFileHandle: 句柄实例。
fileHandleForUpdatingAtPath
Section titled “fileHandleForUpdatingAtPath”以读写方式打开文件。
static fileHandleForUpdatingAtPath(path: string): NSFileHandleParameters:
| Name | Type | Description |
|---|---|---|
path | string | 文件路径。 |
Return Value:
NSFileHandle: 句柄实例。
fileHandleForReadingFromURLError
Section titled “fileHandleForReadingFromURLError”从 URL 以只读方式打开。
static fileHandleForReadingFromURLError(url: NSURL, error: any): NSFileHandleParameters:
| Name | Type | Description |
|---|---|---|
url | NSURL | 文件 URL。 |
error | any | 输出参数,接收错误。 |
Return Value:
NSFileHandle: 句柄实例。
fileHandleForWritingToURLError
Section titled “fileHandleForWritingToURLError”从 URL 以只写方式打开。
static fileHandleForWritingToURLError(url: NSURL, error: any): NSFileHandleParameters:
| Name | Type | Description |
|---|---|---|
url | NSURL | 文件 URL。 |
error | any | 输出参数,接收错误。 |
Return Value:
NSFileHandle: 句柄实例。
fileHandleForUpdatingURLError
Section titled “fileHandleForUpdatingURLError”从 URL 以读写方式打开。
static fileHandleForUpdatingURLError(url: NSURL, error: any): NSFileHandleParameters:
| Name | Type | Description |
|---|---|---|
url | NSURL | 文件 URL。 |
error | any | 输出参数,接收错误。 |
Return Value:
NSFileHandle: 句柄实例。
实例成员 (Instance members)
Section titled “实例成员 (Instance members)”availableData
Section titled “availableData”当前可读数据(非阻塞)。
availableData(): NSDataReturn Value:
NSData: 可读数据。
readDataToEndOfFile
Section titled “readDataToEndOfFile”读取到文件末尾。
readDataToEndOfFile(): NSDataReturn Value:
NSData: 读取的数据。
readDataOfLength
Section titled “readDataOfLength”读取指定长度。
readDataOfLength(length: number): NSDataParameters:
| Name | Type | Description |
|---|---|---|
length | number | 字节数。 |
Return Value:
NSData: 读取的数据。
writeData
Section titled “writeData”写入数据。
writeData(data: NSData): voidParameters:
| Name | Type | Description |
|---|---|---|
data | NSData | 要写入的数据。 |
Return Value:
- 无。
offsetInFile
Section titled “offsetInFile”当前文件偏移。
offsetInFile(): numberReturn Value:
number: 偏移量(字节)。
seekToEndOfFile
Section titled “seekToEndOfFile”移动到文件末尾。
seekToEndOfFile(): numberReturn Value:
number: 新偏移量。
seekToFileOffset
Section titled “seekToFileOffset”移动到指定偏移。
seekToFileOffset(offset: number): voidParameters:
| Name | Type | Description |
|---|---|---|
offset | number | 偏移量(字节)。 |
Return Value:
- 无。
truncateFileAtOffset
Section titled “truncateFileAtOffset”在指定偏移处截断文件。
truncateFileAtOffset(offset: number): voidParameters:
| Name | Type | Description |
|---|---|---|
offset | number | 偏移量。 |
Return Value:
- 无。
synchronizeFile
Section titled “synchronizeFile”同步到磁盘。
synchronizeFile(): voidReturn Value:
- 无。
closeFile
Section titled “closeFile”关闭文件。
closeFile(): voidReturn Value:
- 无。
readInBackgroundAndNotify
Section titled “readInBackgroundAndNotify”在后台读取并发送通知(较少用)。
readInBackgroundAndNotify(): voidReturn Value:
- 无。
readInBackgroundAndNotifyForModes
Section titled “readInBackgroundAndNotifyForModes”在指定 run loop 模式下后台读取并通知。
readInBackgroundAndNotifyForModes(modes: NSArray): voidParameters:
| Name | Type | Description |
|---|---|---|
modes | NSArray | run loop 模式数组。 |
Return Value:
- 无。
readToEndOfFileInBackgroundAndNotify
Section titled “readToEndOfFileInBackgroundAndNotify”在后台读取到末尾并通知。
readToEndOfFileInBackgroundAndNotify(): voidReturn Value:
- 无。
readToEndOfFileInBackgroundAndNotifyForModes
Section titled “readToEndOfFileInBackgroundAndNotifyForModes”在指定模式下后台读取到末尾并通知。
readToEndOfFileInBackgroundAndNotifyForModes(modes: NSArray): voidParameters:
| Name | Type | Description |
|---|---|---|
modes | NSArray | run loop 模式数组。 |
Return Value:
- 无。
acceptConnectionInBackgroundAndNotify
Section titled “acceptConnectionInBackgroundAndNotify”在后台接受连接并通知(较少用)。
acceptConnectionInBackgroundAndNotify(): voidReturn Value:
- 无。
acceptConnectionInBackgroundAndNotifyForModes
Section titled “acceptConnectionInBackgroundAndNotifyForModes”在指定模式下后台接受连接并通知。
acceptConnectionInBackgroundAndNotifyForModes(modes: NSArray): voidParameters:
| Name | Type | Description |
|---|---|---|
modes | NSArray | run loop 模式数组。 |
Return Value:
- 无。
waitForDataInBackgroundAndNotify
Section titled “waitForDataInBackgroundAndNotify”在后台等待数据并通知。
waitForDataInBackgroundAndNotify(): voidReturn Value:
- 无。
waitForDataInBackgroundAndNotifyForModes
Section titled “waitForDataInBackgroundAndNotifyForModes”在指定模式下后台等待数据并通知。
waitForDataInBackgroundAndNotifyForModes(modes: NSArray): voidParameters:
| Name | Type | Description |
|---|---|---|
modes | NSArray | run loop 模式数组。 |
Return Value:
- 无。
fileDescriptor
Section titled “fileDescriptor”底层文件描述符。
fileDescriptor(): numberReturn Value:
number: 文件描述符。