Reads the contents of the specified file and returns a buffer.
Syntax
Windows.Storage.FileIO.readBufferAsync(file).done( /* Your success and error handlers */ );
Parameters
- file
-
Type: IStorageFile
The file to read.
Return value
Type: IAsyncOperation<IBuffer>
When this method completes, it returns an object (type IBuffer) that represents the contents of the file.
Examples
The File Access sample shows you how to use writeTextAsync(file, contents) to write text to a file, like this:
if (file !== null) { Windows.Storage.FileIO.readBufferAsync(sampleFile).then(function (buffer) { // Perform additional tasks after file is read // Use a dataReader object to read from the buffer var dataReader = Windows.Storage.Streams.DataReader.fromBuffer(buffer); var fileContent = dataReader.readString(buffer.length); dataReader.close(); }, // Handle errors with an error function function (error) { // Handle errors encountered during write }); }
In the example, file is a local variable that contains a storageFile that represents the file to read.
After readTextAsync completes, the buffer variable gets the contents of the file as an IBuffer object. You can then read from the buffer using a dataReader object and process the file contents as appropriate (as shown in the example.)
Requirements
|
Minimum supported client | Windows 8 |
|---|---|
|
Minimum supported server | Windows Server 2012 |
|
Namespace |
|
|
Metadata |
|
See also
Build date: 2/25/2013