Can't save file to disk, no clue why
-
29-06-2021 - |
Pregunta
I'm trying to write a string to disk:
return [fileContent writeToFile:path atomically:YES encoding:NSUnicodeStringEncoding error:error];
But it always fails with the following error:
Error Domain=NSCocoaErrorDomain Code=4 "The folder “ddd.csv” doesn’t exist." UserInfo=0xc4a08b0 {NSUnderlyingError=0xc49ba60 "The operation couldn’t be completed. No such file or directory", NSFilePath=file://<path to file>, NSUserStringVariant=Folder}
The path to the file seems to be valid (I've obscured it here) and the string (NSMutableString) is definitely not 0 length. This code used to work before Mountain Lion. Can anyone help shed a light on what could be going on?
Edit:
The value of path
is: file://localhost/Users/cocoaster/Downloads/ddd.csv
Solución
Since you're using a save panel the result comes back as a URL, so if you need a path, convert the result to a path with the path command: [url path].
Alternately, you can use writeToURL:atomically: if that version is available for whatever class fileContent is.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow