---
title: "dataWithContentsOfFile:options:error:"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsdata/datawithcontentsoffile:options:error:"
---

# dataWithContentsOfFile:options:error:

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

## Declaration

```occ
+ (instancetype) dataWithContentsOfFile:(NSString *) path options:(NSDataReadingOptions) readOptionsMask error:(NSError **) errorPtr;
```

## Parameters

- `path`: The absolute path of the file from which to read data.
- `readOptionsMask`: A mask that specifies options for reading the data. Constant components are described in doc://com.apple.foundation/documentation/Foundation/NSData/ReadingOptions.
- `errorPtr`: If an error occurs, upon return contains an error object that describes the problem.

## Discussion

Discussion This method returns nil if the data object could not be created. In this case, errorPtr will contain an NSError indicating the problem.

## See Also

### Reading Data from a File

- [dataWithContentsOfFile:](foundation/nsdata/datawithcontentsoffile:.md)
- [init(contentsOfFile:)](foundation/nsdata/init(contentsoffile:).md)
- [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)
