<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileHandle/init(forWritingAtPath:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileHandle(cm)fileHandleForWritingAtPath:"
  },
  "title" : "init(forWritingAtPath:)"
}
-->

# init(forWritingAtPath:)

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

```
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(_:)`](/documentation/Foundation/FileHandle/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

[`write(_:)`](/documentation/Foundation/FileHandle/write(_:))

Writes the specified data synchronously to the file handle.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)