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

# init(contentsOfFile:)

Initializes a data object with the content of the file at a given path.

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

## Parameters

`path`

The absolute path of the file from which to read data.

## Return Value

A data object initialized by reading into it the data from the file specified by `path`.

## Discussion

This method is equivalent to [`init(contentsOfFile:options:)`](/documentation/Foundation/NSData/init(contentsOfFile:options:)) with no options.

## See Also

[`+  dataWithContentsOfFile:`](/documentation/Foundation/NSData/dataWithContentsOfFile:)

Creates a data object by reading every byte from the file at a given path.



---

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)