Reads the contents of the specified file and returns text.
Syntax
Windows.Storage.FileIO.readTextAsync(file).done( /* Your success and error handlers */ );
Parameters
- file
-
Type: IStorageFile
The file to read.
Return value
Type: IAsyncOperation<String>
When this method completes successfully, it returns the contents of the file as a text string.
Remarks
This method uses the character encoding of the specified file. If you want to specify different encoding, call ReadTextAsync(IStorageFile, UnicodeEncoding) instead.
Examples
The File Access sample shows you how to use readTextAsync(file) to read text from a file, like this:
if (file !== null) { Windows.Storage.FileIO.readTextAsync(file).done(function (fileContent) { // Process content read from the file }, // Handle errors with an error function function (error) { // Handle errors encountered during read }); }
In the example, file is a local variable that contains a storageFile that represents the file to read.
After readTextAsync completes, the fileContent variable gets the contents of the file as a text string. You can then process the contents as appropriate.
Requirements
|
Minimum supported client | Windows 8 |
|---|---|
|
Minimum supported server | Windows Server 2012 |
|
Namespace |
|
|
Metadata |
|
See also
Build date: 2/25/2013