<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileHandle/init(forReadingFrom:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileHandle(cm)fileHandleForReadingFromURL:error:"
  },
  "title" : "init(forReadingFrom:)"
}
-->

# init(forReadingFrom:)

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

```
convenience init(forReadingFrom url: URL) throws
```

## Parameters

`url`

The URL of the file, device, or named socket to access.

## Return Value

The initialized file handle object or `nil` if no file exists at `url`.

## Discussion

The file pointer is set to the beginning of the file. You cannot write data to the returned file handle object.
Use the [`readDataToEndOfFile()`](/documentation/Foundation/FileHandle/readDataToEndOfFile()) or [`readData(ofLength:)`](/documentation/Foundation/FileHandle/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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)