Writes all of contents
to a file named filename
, with good error checking.
If a file called filename
already exists it will be overwritten.
This write is atomic in the sense that it is first written to a temporary file which is then renamed to the final name. Notes:
filename
already exists hard links to filename
will break. Also since the file is recreated,
existing permissions, access control lists, metadata etc. may be lost. If filename
is a symbolic link, the link itself
will be replaced, not the linked file.filename
already exists and is open.If the call was successful, it returns true. If the call was not successful, it returns false and sets throws. The error domain is FileError. Possible error codes are those in the FileError enumeration.
Note that the name for the temporary file is constructed by appending up to 7 characters to filename
.
filename |
name of a file to write |
contents |
string to write to the file |
length |
length of |
true on success, false if an error occurred |