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

# dataWithContentsOfFile:

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

## Declaration

```occ
+ (instancetype) dataWithContentsOfFile:(NSString *) path;
```

## Parameters

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

## Discussion

Discussion This method returns nil if the data object could not be created. If you need to know the reason for failure, use dataWithContentsOfFile:options:error:. This method is equivalent to calling dataWithContentsOfFile:options:error: and passing no options. A sample using this method can be found in Working With Binary Data.

## See Also

### Reading Data from a File

- [dataWithContentsOfFile:options:error:](foundation/nsdata/datawithcontentsoffile:options:error:.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)
