---
title: "init(forWritingAtPath:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/filehandle/init(forwritingatpath:)"
---

# init(forWritingAtPath:)

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

## Declaration

```swift
convenience init?(forWritingAtPath path: String)
```

## Parameters

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

## Return Value

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

## Discussion

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

### Related Documentation

- [write(_:)](foundation/filehandle/write(_:).md)

### Creating a file handle

- [init(fileDescriptor:)](foundation/filehandle/init(filedescriptor:).md)
- [init(fileDescriptor:closeOnDealloc:)](foundation/filehandle/init(filedescriptor:closeondealloc:).md)
- [init(forReadingAtPath:)](foundation/filehandle/init(forreadingatpath:).md)
- [init(forReadingFromURL:)](foundation/filehandle/init(forreadingfromurl:).md)
- [init(forWritingToURL:)](foundation/filehandle/init(forwritingtourl:).md)
- [init(forUpdatingAtPath:)](foundation/filehandle/init(forupdatingatpath:).md)
- [init(forUpdatingURL:)](foundation/filehandle/init(forupdatingurl:).md)
- [init(coder:)](foundation/filehandle/init(coder:).md)
