---
title: "init(contentsOfFile:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nsdata/init(contentsoffile:)"
---

# init(contentsOfFile:)

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

## Declaration

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

## Parameters

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

## Return Value

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

## Discussion

Discussion This method is equivalent to init(contentsOfFile:options:) with no options.

## See Also

### Reading Data from a File

- [init(contentsOfFile:options:)](foundation/nsdata/init(contentsoffile:options:).md)
- [NSData.ReadingOptions](foundation/nsdata/readingoptions.md)
- [init(contentsOfMappedFile:)](foundation/nsdata/init(contentsofmappedfile:).md)
- [dataWithContentsOfMappedFile(_:)](foundation/nsdata/datawithcontentsofmappedfile(_:).md)
