Initializer

init(forWritingAtPath:)

Returns a file handle initialized for writing to the file, device, or named socket at the specified path.

Declaration

convenience init?(forWritingAtPath path: String)

Parameters

path

The path to the file, device, or named socket to access.

Return Value

The initialized file handle object or nil if no file exists at path.

Discussion

The file pointer is set to the beginning of the file. You cannot read data from the returned file handle object. Use the write(_:) method to write data to the file handle.

When using this method to create a file handle object, the file handle owns its associated file descriptor and is responsible for closing it.

See Also

Getting a File Handle

init?(forReadingAtPath: String)

Returns a file handle initialized for reading the file, device, or named socket at the specified path.

init(forReadingFrom: URL)

Returns a file handle initialized for reading the file, device, or named socket at the specified URL.

init(forWritingTo: URL)

Returns a file handle initialized for writing to the file, device, or named socket at the specified URL.

init?(forUpdatingAtPath: String)

Returns a file handle initialized for reading and writing to the file, device, or named socket at the specified path.

init(forUpdating: URL)

Returns a file handle initialized for reading and writing to the file, device, or named socket at the specified URL.

class var standardError: FileHandle

Returns the file handle associated with the standard error file.

class var standardInput: FileHandle

Returns the file handle associated with the standard input file.

class var standardOutput: FileHandle

Returns the file handle associated with the standard output file.

class var nullDevice: FileHandle

Returns a file handle associated with a null device.