---
title: "write(toFile:atomically:encoding:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/stringprotocol/write(tofile:atomically:encoding:)"
---

# write(toFile:atomically:encoding:)

Writes the contents of the String to a file at a given path using a given encoding.

## Declaration

```swift
func write<T>(toFile path: T, atomically useAuxiliaryFile: Bool, encoding enc: String.Encoding) throws where T : StringProtocol
```
