<!--
{
  "availability" : [
    "macCatalyst: -",
    "macOS: 10.0.0 - 10.4.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSDocument/readFromFile:ofType:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDocument(im)readFromFile:ofType:"
  },
  "title" : "readFromFile:ofType:"
}
-->

# readFromFile:ofType:

Reads and loads document data of the given type from the given file.

```
- (BOOL) readFromFile:(NSString *) fileName ofType:(NSString *) type;
```

## Discussion

Reads and loads document data of type `docType` from the file `fileName`, returning whether the operation was successful. This method invokes `loadDataRepresentation:ofType:` and is invoked when the receiver is first created and initialized by `initWithContentsOfFile:ofType:`. It uses `NSData` <doc://com.apple.documentation/documentation/Foundation/NSData/init(contentsOfFile:)> to get the document data.

This method is one of the location-based primitives. Subclasses can override this method instead of overriding `loadDataRepresentation:ofType:` to read and load document data. Subclasses that handle file packages such as RTFD or that treat locations of files as anything other than paths should override this method. Override implementations of this method can filter the document data using `NSPasteboard` or other filtering services.

---

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)