API参考Foundation

NSFileHandle

文件句柄(读写文件/标准输入输出)。

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

类成员 (Class members)

fileHandleWithStandardInput

标准输入句柄。

static fileHandleWithStandardInput(): NSFileHandle

Return Value:

  • NSFileHandle: 标准输入句柄。

fileHandleWithStandardOutput

标准输出句柄。

static fileHandleWithStandardOutput(): NSFileHandle

Return Value:

  • NSFileHandle: 标准输出句柄。

fileHandleWithStandardError

标准错误句柄。

static fileHandleWithStandardError(): NSFileHandle

Return Value:

  • NSFileHandle: 标准错误句柄。

fileHandleWithNullDevice

空设备句柄。

static fileHandleWithNullDevice(): NSFileHandle

Return Value:

  • NSFileHandle: 空设备句柄。

fileHandleForReadingAtPath

以只读方式打开文件。

static fileHandleForReadingAtPath(path: string): NSFileHandle

Parameters:

NameTypeDescription
pathstring文件路径。

Return Value:

  • NSFileHandle: 句柄实例。

fileHandleForWritingAtPath

以只写方式打开文件。

static fileHandleForWritingAtPath(path: string): NSFileHandle

Parameters:

NameTypeDescription
pathstring文件路径。

Return Value:

  • NSFileHandle: 句柄实例。

fileHandleForUpdatingAtPath

以读写方式打开文件。

static fileHandleForUpdatingAtPath(path: string): NSFileHandle

Parameters:

NameTypeDescription
pathstring文件路径。

Return Value:

  • NSFileHandle: 句柄实例。

fileHandleForReadingFromURLError

从 URL 以只读方式打开。

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

Parameters:

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

Return Value:

  • NSFileHandle: 句柄实例。

fileHandleForWritingToURLError

从 URL 以只写方式打开。

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

Parameters:

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

Return Value:

  • NSFileHandle: 句柄实例。

fileHandleForUpdatingURLError

从 URL 以读写方式打开。

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

Parameters:

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

Return Value:

  • NSFileHandle: 句柄实例。

实例成员 (Instance members)

availableData

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

availableData(): NSData

Return Value:

  • NSData: 可读数据。

readDataToEndOfFile

读取到文件末尾。

readDataToEndOfFile(): NSData

Return Value:

  • NSData: 读取的数据。

readDataOfLength

读取指定长度。

readDataOfLength(length: number): NSData

Parameters:

NameTypeDescription
lengthnumber字节数。

Return Value:

  • NSData: 读取的数据。

writeData

写入数据。

writeData(data: NSData): void

Parameters:

NameTypeDescription
dataNSData要写入的数据。

Return Value:

  • 无。

offsetInFile

当前文件偏移。

offsetInFile(): number

Return Value:

  • number: 偏移量(字节)。

seekToEndOfFile

移动到文件末尾。

seekToEndOfFile(): number

Return Value:

  • number: 新偏移量。

seekToFileOffset

移动到指定偏移。

seekToFileOffset(offset: number): void

Parameters:

NameTypeDescription
offsetnumber偏移量(字节)。

Return Value:

  • 无。

truncateFileAtOffset

在指定偏移处截断文件。

truncateFileAtOffset(offset: number): void

Parameters:

NameTypeDescription
offsetnumber偏移量。

Return Value:

  • 无。

synchronizeFile

同步到磁盘。

synchronizeFile(): void

Return Value:

  • 无。

closeFile

关闭文件。

closeFile(): void

Return Value:

  • 无。

readInBackgroundAndNotify

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

readInBackgroundAndNotify(): void

Return Value:

  • 无。

readInBackgroundAndNotifyForModes

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

readInBackgroundAndNotifyForModes(modes: NSArray): void

Parameters:

NameTypeDescription
modesNSArrayrun loop 模式数组。

Return Value:

  • 无。

readToEndOfFileInBackgroundAndNotify

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

readToEndOfFileInBackgroundAndNotify(): void

Return Value:

  • 无。

readToEndOfFileInBackgroundAndNotifyForModes

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

readToEndOfFileInBackgroundAndNotifyForModes(modes: NSArray): void

Parameters:

NameTypeDescription
modesNSArrayrun loop 模式数组。

Return Value:

  • 无。

acceptConnectionInBackgroundAndNotify

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

acceptConnectionInBackgroundAndNotify(): void

Return Value:

  • 无。

acceptConnectionInBackgroundAndNotifyForModes

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

acceptConnectionInBackgroundAndNotifyForModes(modes: NSArray): void

Parameters:

NameTypeDescription
modesNSArrayrun loop 模式数组。

Return Value:

  • 无。

waitForDataInBackgroundAndNotify

在后台等待数据并通知。

waitForDataInBackgroundAndNotify(): void

Return Value:

  • 无。

waitForDataInBackgroundAndNotifyForModes

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

waitForDataInBackgroundAndNotifyForModes(modes: NSArray): void

Parameters:

NameTypeDescription
modesNSArrayrun loop 模式数组。

Return Value:

  • 无。

fileDescriptor

底层文件描述符。

fileDescriptor(): number

Return Value:

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

正在加载...

协议:JSBNSFileHandle,来源:-