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