---
title: "init(forReadingAtPath:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/filehandle/init(forreadingatpath:)"
---

# init(forReadingAtPath:)

Returns a file handle initialized for reading the file, device, or named socket at the specified path.

## Declaration

```swift
convenience init?(forReadingAtPath path: String)
```

## Parameters

- `path`: The path to the file, device, or named socket to access.

## Return Value

Return Value The initialized file handle object or nil if no file exists at path.

## Discussion

Discussion The system sets the file pointer to the beginning of the file. You can’t write data to the returned file handle object. Use the readDataToEndOfFile() or readData(ofLength:) methods to read data from it. When using this method to create a file handle object, the file handle owns its associated file descriptor and is responsible for closing it.

## See Also

### Related Documentation

- [availableData](foundation/filehandle/availabledata.md)
- [readData(ofLength:)](foundation/filehandle/readdata(oflength:).md)
- [readDataToEndOfFile()](foundation/filehandle/readdatatoendoffile().md)

### Creating a file handle

- [init(fileDescriptor:)](foundation/filehandle/init(filedescriptor:).md)
- [init(fileDescriptor:closeOnDealloc:)](foundation/filehandle/init(filedescriptor:closeondealloc:).md)
- [init(forReadingFromURL:)](foundation/filehandle/init(forreadingfromurl:).md)
- [init(forWritingAtPath:)](foundation/filehandle/init(forwritingatpath:).md)
- [init(forWritingToURL:)](foundation/filehandle/init(forwritingtourl:).md)
- [init(forUpdatingAtPath:)](foundation/filehandle/init(forupdatingatpath:).md)
- [init(forUpdatingURL:)](foundation/filehandle/init(forupdatingurl:).md)
- [init(coder:)](foundation/filehandle/init(coder:).md)
