---
title: "arrayWithContentsOfFile:"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsarray/arraywithcontentsoffile:"
---

# arrayWithContentsOfFile:

Creates and returns an array containing the contents of the file specified by a given path.

## Declaration

```occ
+ (NSArray<id> *) arrayWithContentsOfFile:(NSString *) path;
```

## Parameters

- `path`: The path to a file containing a string representation of an array produced by the doc://com.apple.foundation/documentation/Foundation/NSArray/write(toFile:atomically:) method.

## Return Value

Return Value An array containing the contents of the file specified by aPath. Returns nil if the file can’t be opened or if the contents of the file can’t be parsed into an array.

## Discussion

Discussion The array representation in the file identified by aPath must contain only property list objects (NSString, NSData, NSDate, NSNumber, NSArray, or NSDictionary objects). For more details, see Property List Programming Guide. The objects contained by this array are immutable, even if the array is mutable.

## See Also

### Related Documentation

- [write(toFile:atomically:)](foundation/nsarray/write(tofile:atomically:).md)

### Creating an Array

- [array](foundation/nsarray/array.md)
- [arrayWithArray:](foundation/nsarray/arraywitharray:.md)
- [init(object:)](foundation/nsarray/init(object:).md)
- [arrayWithObjects:](foundation/nsarray/arraywithobjects:.md)
- [init(objects:count:)](foundation/nsarray/init(objects:count:)-7dct1.md)
