我正在尝试将一些数据存储在文件中。我在第一次迭代时打开文件,然后添加信息。但是,当算法结束时,文件大小是 5kbs,它必须是 2,5 Mbs。
if (!isopen)
{
NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// Check DD
if ([paths count] > 0)
{
NSLog(@"Found a path");
fichero2 = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"out2.raw"];
NSLog(@"path %@",fichero2);
} else {
//d'oh, something went really wrong
NSLog(@"ERROR: could not open %s\n", "out.raw");
return -1;
}
isopen = 1;
}
else
{
// Write file
NSMutableData *data = [NSMutableData dataWithLength:1152*2];
[data appendBytes:((SInt16 *)[audioProcessor audioBuffer].mData) length:1152*2];
[data writeToFile:fichero2 atomically:YES];
}
真的需要关闭文件吗?它会自动关闭吗?那么,为什么不存储数据呢?