我试图把我的照片中的图像合并成一个档案,并写到磁盘上。
NSMutableArray *array = [NSMutableArray arrayWithObjects:
[NSData dataWithContentsOfFile:@"0.png"],
[NSData dataWithContentsOfFile:@"1.png"],
[NSData dataWithContentsOfFile:@"2.png"],
nil];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:array];
NSErr或 *err或 = nil;
NSString *path=@"/Users/myusername/Desktop/_stuff.dat";
[data writeToFile:path options:NSDataWritingAtomic err或:&err或];
或
NSArray *array = [NSArray arrayWithObjects:
[NSImage imageNamed:@"0"],
[NSImage imageNamed:@"1"],
[NSImage imageNamed:@"2"],
nil];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:array];
NSErr或 *err或 = nil;
NSString *path=@"/Users/myusername/Desktop/_stuff.dat";
[data writeToFile:path options:NSDataWritingAtomic err或:&err或];
But both produce a file that is 4KB (empty). If I NSLog
the err或 it is (null)
. Am I making the data the wrong way?
Edit: If I open the resulting file with a text edit或, it looks like this: