// // main.m // NSFileHandler // // Created by MAC on 15/12/26. // Copyright © 2015年 MAC. All rights reserved. // #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { // NSFileHandler 可以读取图片 接口 管道 //读取 NSString *path = @"/tmp/test100000.txt"; NSFileHandle *readingHandle = [NSFileHandle fileHandleForReadingAtPath:path]; NSData *data = [readingHandle readDataToEndOfFile]; NSString *str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"%@",str); //写 NSString *path1 = @"/tmp/test100000.txt"; NSFileHandle *writingHandle = [NSFileHandle fileHandleForWritingAtPath:path1]; NSString *string = @"hahahahahahhaa"; data = [string dataUsingEncoding:NSUTF8StringEncoding]; [writingHandle writeData:data]; //更新 NSString *path2 = @"/tmp/test2.txt"; NSFileHandle *updatingHandle = [NSFileHandle fileHandleForUpdatingAtPath:path2]; } return 0; }
时间: 2024-10-11 22:16:22