Skip to content

NSFileHandle

NSFileHandle 表示一个文件句柄,可用于读取/写入数据,或访问标准输入/输出/错误。

标准输入句柄。

static fileHandleWithStandardInput(): NSFileHandle

Return Value:

  • NSFileHandle: 标准输入句柄。

标准输出句柄。

static fileHandleWithStandardOutput(): NSFileHandle

Return Value:

  • NSFileHandle: 标准输出句柄。

标准错误句柄。

static fileHandleWithStandardError(): NSFileHandle

Return Value:

  • NSFileHandle: 标准错误句柄。

空设备句柄。

static fileHandleWithNullDevice(): NSFileHandle

Return Value:

  • NSFileHandle: 空设备句柄。

以只读方式打开文件。

static fileHandleForReadingAtPath(path: string): NSFileHandle

Parameters:

NameTypeDescription
pathstring文件路径。

Return Value:

  • NSFileHandle: 句柄实例。

以只写方式打开文件。

static fileHandleForWritingAtPath(path: string): NSFileHandle

Parameters:

NameTypeDescription
pathstring文件路径。

Return Value:

  • NSFileHandle: 句柄实例。

以读写方式打开文件。

static fileHandleForUpdatingAtPath(path: string): NSFileHandle

Parameters:

NameTypeDescription
pathstring文件路径。

Return Value:

  • NSFileHandle: 句柄实例。

从 URL 以只读方式打开。

static fileHandleForReadingFromURLError(url: NSURL, error: any): NSFileHandle

Parameters:

NameTypeDescription
urlNSURL文件 URL。
errorany输出参数,接收错误。

Return Value:

  • NSFileHandle: 句柄实例。

从 URL 以只写方式打开。

static fileHandleForWritingToURLError(url: NSURL, error: any): NSFileHandle

Parameters:

NameTypeDescription
urlNSURL文件 URL。
errorany输出参数,接收错误。

Return Value:

  • NSFileHandle: 句柄实例。

从 URL 以读写方式打开。

static fileHandleForUpdatingURLError(url: NSURL, error: any): NSFileHandle

Parameters:

NameTypeDescription
urlNSURL文件 URL。
errorany输出参数,接收错误。

Return Value:

  • NSFileHandle: 句柄实例。

当前可读数据(非阻塞)。

availableData(): NSData

Return Value:

  • NSData: 可读数据。

读取到文件末尾。

readDataToEndOfFile(): NSData

Return Value:

  • NSData: 读取的数据。

读取指定长度。

readDataOfLength(length: number): NSData

Parameters:

NameTypeDescription
lengthnumber字节数。

Return Value:

  • NSData: 读取的数据。

写入数据。

writeData(data: NSData): void

Parameters:

NameTypeDescription
dataNSData要写入的数据。

Return Value:

  • 无。

当前文件偏移。

offsetInFile(): number

Return Value:

  • number: 偏移量(字节)。

移动到文件末尾。

seekToEndOfFile(): number

Return Value:

  • number: 新偏移量。

移动到指定偏移。

seekToFileOffset(offset: number): void

Parameters:

NameTypeDescription
offsetnumber偏移量(字节)。

Return Value:

  • 无。

在指定偏移处截断文件。

truncateFileAtOffset(offset: number): void

Parameters:

NameTypeDescription
offsetnumber偏移量。

Return Value:

  • 无。

同步到磁盘。

synchronizeFile(): void

Return Value:

  • 无。

关闭文件。

closeFile(): void

Return Value:

  • 无。

在后台读取并发送通知(较少用)。

readInBackgroundAndNotify(): void

Return Value:

  • 无。

在指定 run loop 模式下后台读取并通知。

readInBackgroundAndNotifyForModes(modes: NSArray): void

Parameters:

NameTypeDescription
modesNSArrayrun loop 模式数组。

Return Value:

  • 无。

在后台读取到末尾并通知。

readToEndOfFileInBackgroundAndNotify(): void

Return Value:

  • 无。

readToEndOfFileInBackgroundAndNotifyForModes

Section titled “readToEndOfFileInBackgroundAndNotifyForModes”

在指定模式下后台读取到末尾并通知。

readToEndOfFileInBackgroundAndNotifyForModes(modes: NSArray): void

Parameters:

NameTypeDescription
modesNSArrayrun loop 模式数组。

Return Value:

  • 无。

在后台接受连接并通知(较少用)。

acceptConnectionInBackgroundAndNotify(): void

Return Value:

  • 无。

acceptConnectionInBackgroundAndNotifyForModes

Section titled “acceptConnectionInBackgroundAndNotifyForModes”

在指定模式下后台接受连接并通知。

acceptConnectionInBackgroundAndNotifyForModes(modes: NSArray): void

Parameters:

NameTypeDescription
modesNSArrayrun loop 模式数组。

Return Value:

  • 无。

在后台等待数据并通知。

waitForDataInBackgroundAndNotify(): void

Return Value:

  • 无。

在指定模式下后台等待数据并通知。

waitForDataInBackgroundAndNotifyForModes(modes: NSArray): void

Parameters:

NameTypeDescription
modesNSArrayrun loop 模式数组。

Return Value:

  • 无。

底层文件描述符。

fileDescriptor(): number

Return Value:

  • number: 文件描述符。
头文件 API 清单

正在加载…

协议:,来源: