Instance Method


Creates a file with the specified content and attributes at the given location.


- (BOOL)createFileAtPath:(NSString *)path contents:(NSData *)data attributes:(NSDictionary<NSString *,id> *)attr;



The path for the new file.


A data object containing the contents of the new file.


A dictionary containing the attributes to associate with the new file. You can use these attributes to set the owner and group numbers, file permissions, and modification date. For a list of keys, see File Attribute Keys. If you specify nil for attributes, the file is created with a set of default attributes.

Return Value

YES if the operation was successful or if the item already exists, otherwise NO.


If you specify nil for the attributes parameter, this method uses a default set of values for the owner, group, and permissions of any newly created directories in the path. Similarly, if you omit a specific attribute, the default value is used. The default values for newly created files are as follows:

  • Permissions are set according to the umask of the current process. For more information, see umask.

  • The owner ID is set to the effective user ID of the process.

  • The group ID is set to that of the parent directory.

If a file already exists at path, this method overwrites the contents of that file if the current process has the appropriate privileges to do so.

See Also

Related Symbols

- attributesOfItemAtPath:error:

Returns the attributes of the item at a given path.

- contentsAtPath:

Returns the contents of the file at the specified path.

- setAttributes:ofItemAtPath:error:

Sets the attributes of the specified file or directory.