I want to add contents to file2(file2 already contains content and should not be replaced) from a file1. copyItemAtPath throws error as file2 already exists.Is there a way to just add contents to a file instead of replacing existing contents.
if(![[NSFileManager defaultManager] fileExistsAtPath:logPath2])
[[NSFileManager defaultManager] createFileAtPath:logPath2 contents:[NSData data] attributes:nil];
if ([filemgr copyItemAtPath: logPath1 toPath:
logPath2 error: &err])
NSLog (@"Temp Move successful");
else
NSLog (@"Temp Move failed %@",err);
使用NSFileManager
不可能做到这一点,但是您可以使用-[NSOutputStream outputStreamToFileAtPath:append:]
( 文档 )来实现此目的。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.