<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 8.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/String/init(contentsOfFile:usedEncoding:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SS10FoundationE14contentsOfFile12usedEncodingS2Sh_SSAAE0F0VztKcfc"
  },
  "title" : "init(contentsOfFile:usedEncoding:)"
}
-->

# init(contentsOfFile:usedEncoding:)

Produces a string created by reading data from the file at a given path and returns by reference the encoding used to interpret the file.

```
init(contentsOfFile path: String, usedEncoding: inout String.Encoding) throws
```

---

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)