初始化
- (instancetype)initWithFileDescriptor:(int)fd closeOnDealloc:(BOOL)closeopt
根据文件描述符初始化对象。fd为文件描述符,closeopt表示是否在释放对象时关闭文件。
- (instancetype)initWithFileDescriptor:(int)fd;
根据文件描述符初始化对象。fd为文件描述符。
@property (readonly) int fileDescriptor;
返回文件描述符
构造对象
+ (nullable instancetype)fileHandleForReadingAtPath:(NSString *)path;
构造读取文件对象。参数path为文件路径。
+ (nullable instancetype)fileHandleForWritingAtPath:(NSString *)path;
构造写入文件对象。参数path为文件路径。
+ (nullable instancetype)fileHandleForUpdatingAtPath:(NSString *)path;
构造更新文件对象。参数path为文件路径。
+ (nullable instancetype)fileHandleForReadingFromURL:(NSURL *)url error:(NSError **)error
构造读取URL对象。
+ (nullable instancetype)fileHandleForWritingToURL:(NSURL *)url error:(NSError **)error
构造写入URL对象。
+ (nullable instancetype)fileHandleForUpdatingURL:(NSURL *)url error:(NSError **)error
构造更新URL对象。
标准对象
@property (class, readonly, strong) NSFileHandle *fileHandleWithStandardInput;
标准输入文件对象
@property (class, readonly, strong) NSFileHandle *fileHandleWithStandardOutput;
标准输出文件对象
@property (class, readonly, strong) NSFileHandle *fileHandleWithStandardError;
标准出错文件对象
@property (class, readonly, strong) NSFileHandle *fileHandleWithNullDevice;
空设备文件对象
读取写入
@property (readonly, copy) NSData *availableData;
返回可获取的数据
- (NSData *)readDataToEndOfFile;
读取数据到文件末尾
- (NSData *)readDataOfLength:(NSUInteger)length;
读取固定长度的数据
- (void)writeData:(NSData *)data;
写入数据
@property (readonly) unsigned long long offsetInFile;
返回文件偏移
- (unsigned long long)seekToEndOfFile;
跳转到文件末尾
(void)seekToFileOffset:(unsigned long long)offset;
跳转文件
- (void)truncateFileAtOffset:(unsigned long long)offset;
截断文件
- (void)synchronizeFile;
同步文件
- (void)closeFile;
关闭文件