本文介绍了writeToFile在OSX中,追加到文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要不时地写一些数据到一个文件,附加到它。

I need to write some data from time to time to a file, appending to it.

现在我有:

BOOL ok = [[NSString stringWithFormat:@"%f",raw] writeToFile:path atomically:YES encoding:NSUnicodeStringEncoding error:&error];

如何在文件末尾追加 raw

How could I append to the end of the file the new contents of raw?

推荐答案

一种方法是使用fileHandleForWritingAtPath:方法获取NSFileHandle,将NSString转换为NSData然后调用writeData:在你的NSFileHandle上移动文件指针到文件的结尾。

One method would be to obtain a NSFileHandle using fileHandleForWritingAtPath: method, converting your NSString to NSData and then calling writeData: on your NSFileHandle after moving the file pointer to the end of the file.

这篇关于writeToFile在OSX中,追加到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 03:04