Fast way to write data to multiple files - Objective-C OSX
-
29-06-2022 - |
Frage
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?
Keine korrekte Lösung
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow