iOS NSFileHandle详解

来源:互联网 发布:plc与单片机应用场合 编辑:程序博客网 时间:2024/04/30 07:41
NSFileHandle 此类主要是对文件内容进行读取和写入操作(NSFileMange  此类主要是对文件进行的操作以及文件信息的获取)

常用处理方法

@property (readonly, copy) NSData *availableData;//从设备或通道返回可用的数据

-  (NSData *)readDataToEndOfFile; 从当前的节点读取到文件的末尾

- (NSData *)readDataOfLength:(NSUInteger)length; 从当前节点开始读取指定的长度数据

- (void)writeData:(NSData *)data; 写入数据

-  (unsigned longlong)offsetInFile;  获取当前文件的偏移量

-  (unsigned longlong)seekToEndOfFile; 跳到文件末尾

- (void)seekToFileOffset:(unsignedlonglong)offset; 跳到指定文件的偏移量

-  (void)truncateFileAtOffset:(unsignedlong long)offset; 将文件的长度设为offset字节

- (void)synchronizeFile;//同步

-  (void)closeFile;  关闭文件


+ (id)fileHandleForReadingAtPath:(NSString*)path  打开一个文件准备读取

+ (id)fileHandleForWritingAtPath:(NSString *)path  打开一个文件准备写入

+ (id)fileHandleForUpdatingAtPath:(NSString *)path  打开一个文件准备更新



- (instancetype)initWithFileDescriptor:(int)fd;//初始化文件处理对象

@property (readonly) int fileDescriptor;//文件描述符


//异步通信、、高级使用方法移步另一篇博客

- (void)readInBackgroundAndNotifyForModes:(nullable NSArray<NSRunLoopMode> *)modes;
- (void)readInBackgroundAndNotify;

- (void)readToEndOfFileInBackgroundAndNotifyForModes:(nullable NSArray<NSRunLoopMode> *)modes;
- (void)readToEndOfFileInBackgroundAndNotify;

- (void)acceptConnectionInBackgroundAndNotifyForModes:(nullable NSArray<NSRunLoopMode> *)modes;
- (void)acceptConnectionInBackgroundAndNotify;

- (void)waitForDataInBackgroundAndNotifyForModes:(nullable NSArray<NSRunLoopMode> *)modes;
- (void)waitForDataInBackgroundAndNotify;




======================================================================

//NSFileHandle读取


   


//NSFileHandle追加 和 定位




//NSFileHandle复制




//NSFileHandle合并数据





//NSFileHandle文件指针的使用







0 0
原创粉丝点击