<!--
{
  "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/NSCharacterSet/init(contentsOfFile:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCharacterSet(cm)characterSetWithContentsOfFile:"
  },
  "title" : "init(contentsOfFile:)"
}
-->

# init(contentsOfFile:)

Returns a character set read from the bitmap representation stored in the file a given path.

```
init?(contentsOfFile fName: String)
```

## Parameters

`fName`

A path to a file containing a bitmap representation of a character set. The path name must end with the extension `.bitmap`.

## Return Value

A character set read from the bitmap representation stored in the file at `path`.

## Discussion

This method doesn’t use filenames to check for the uniqueness of the character sets it creates. To prevent duplication of character sets in memory, cache them and make them available through an API that checks whether the requested set has already been loaded.

To read a bitmap representation from any file, use the `NSData` method[`dataWithContentsOfFile:options:error:`](/documentation/Foundation/NSData/dataWithContentsOfFile:options:error:) and pass the result to [`init(bitmapRepresentation:)`](/documentation/Foundation/NSCharacterSet/init(bitmapRepresentation:)).

---

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)