标签:
1 #import 2 int main(int argc, const char * argv[]) 3 { 4 @autoreleasepool { 5 6 NSFileHandle *inFile, *outFile; 7 8 NSData *buffer; 9 10 11 12 //打开fileA用于读操作 13 14 inFile = [NSFileHandle fileHandleForReadingAtP 15 16 if(inFile == nil) 17 18 { 19 20 NSLog(@"Open of fileA.txt reading failed") 21 22 return 1; 23 24 } 25 26 27 28 //打开fileB用于更新操作 29 30 outFile = [NSFileHandle fileHandleForWritingAtPath:@"fileB.txt"]; 31 32 if(outFile == nil) 33 34 { 35 36 NSLog(@"Open of fileB for writing failed") 37 38 return 2; 39 40 } 41 42 43 44 //找到并定位到outFile的末尾位置(在此后追加文件) 45 46 [outFile seekToEndOfFile]; 47 48 49 50 //读取inFile并且将其内容写到outFile中 51 52 buffer = [inFile readDataToEndOfFile]; 53 54 [outFile writeData:buffer]; 55 56 57 //关闭读写文件 58 59 [inFile closeFile]; 60 61 [outFile closeFile]; 62 63 } 64 65 return 0; 66 67 }
标签:
原文地址:http://www.cnblogs.com/song-kl/p/4479108.html