Düzenle

Aracılığıyla paylaş


NSData.FromFile Method

Definition

Overloads

FromFile(String)

Creates an NSData by loading the contents of the specified file into memory.

FromFile(String, NSDataReadingOptions, NSError)

Creates an NSData by loading the contents of the specified file into memory.

FromFile(String)

Creates an NSData by loading the contents of the specified file into memory.

[Foundation.Export("dataWithContentsOfFile:")]
public static Foundation.NSData FromFile (string path);
static member FromFile : string -> Foundation.NSData

Parameters

path
String

Path to the filename to wrap as an NSData.

Returns

Newly created NSData object exposing the contents of the file, or null on error.

Attributes

Remarks

This version of FromFile loads the contents of the file into memory on startup, use the M:Foundation.NSData.FromFile(string,Foundation.NSDataReadingOptions,Foundation.Error) to use mmap.

Applies to

FromFile(String, NSDataReadingOptions, NSError)

Creates an NSData by loading the contents of the specified file into memory.

[Foundation.Export("dataWithContentsOfFile:options:error:")]
public static Foundation.NSData FromFile (string path, Foundation.NSDataReadingOptions mask, out Foundation.NSError error);
static member FromFile : string * Foundation.NSDataReadingOptions *  -> Foundation.NSData

Parameters

path
String

Path to the filename to wrap as an NSData.

mask
NSDataReadingOptions

Options can be used to control the file loading, can be used to force the file to be mapped into the VM, instead of loaded by reading the contents.

error
NSError

Returns the error on failure.

Returns

Newly created NSData object exposing the contents of the file, or null on error.

Attributes

Remarks

By default NSData will loads the contents of the file in memory by allocating a block of memory and then reading the contents of the file into it.

The Mapped and MappedAlways parameter instruct NSData to use the kernel's interface to map the file into the process address space. This has a few advantages: instead of allocating read/write memory for the process, that becomes real memory usage, the mapped versions map the file into memory which means that the data is loaded on demand instead of being loaded upfront. This also allows the kernel to discard the data loaded from memory when the system is running low on memory.

Applies to