我正在使用 UIWebView 编写一个富文本编辑器。为此,我使用了一个模板文件作为启动器。
然后,当用户完成编辑但尚未发布时,我想将当前内容保存到备份 html 文件中,以防应用程序损坏。
我怎么做?
给你...伙计
NSFileHandle *file;
NSMutableData *data;
const char *bytestring = "black dog";//In your case html string here
data = [NSMutableData dataWithBytes:bytestring length:strlen(bytestring)];
NSString *path = //Path to your html file
if ([filemgr fileExistsAtPath:path] == YES){
NSLog (@"File exists");
file = [NSFileHandle fileHandleForUpdatingAtPath:path];
if (file == nil)
NSLog(@"Failed to open file");
[file writeData: data];
[file closeFile];
}
else
NSLog (@"File not found");
下面是完整的教程
在 Objective-C 中使用文件 I/O http://www.techotopia.com/index.php/Working_with_Files_in_Objective-C
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)