Question

Currently, I'm serially creating/writing data to ~30,000 files using this code:

    if ([[NSFileManager defaultManager] fileExistsAtPath:[_output_url path]]) {
        //file already exists, append string to it
        NSFileHandle *aFileHandle = [NSFileHandle fileHandleForWritingAtPath:[_output_url path]];
        [aFileHandle seekToEndOfFile];
        [aFileHandle writeData:[dataString dataUsingEncoding:NSUTF8StringEncoding]];
    } else {
        //create file
        [dataString writeToFile:[_output_url path] atomically:YES encoding: NSUTF8StringEncoding error: NULL];
    }

As you can guess, it takes quite a bit of time for this to run through 30k files. However, I'm wondering if there is a way to make this more efficient. I've looked at NSOutputStream - would this be a viable alternative? Or am I always limited by the speed at which the system can write the data to a file?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top