FileIO class
Provides helper methods for reading and writing files that are represented by objects of type IStorageFile.
Syntax
var fileIO = Windows.Storage.FileIO;
Attributes
- MarshalingBehaviorAttribute(Agile)
- StaticAttribute(Windows.Storage.IFileIOStatics, NTDDI_WIN8)
- ThreadingAttribute(Both)
- VersionAttribute(NTDDI_WIN8)
Members
The FileIO class has these types of members:
Methods
The FileIO class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.
| Method | Description |
|---|---|
| AppendLinesAsync(IStorageFile, IIterable(String)) | Appends lines of text to the specified file. |
| AppendLinesAsync(IStorageFile, IIterable(String), UnicodeEncoding) | Appends lines of text to the specified file using the specified character encoding. |
| AppendTextAsync(IStorageFile, String) | Appends text to the specified file. |
| AppendTextAsync(IStorageFile, String, UnicodeEncoding) | Appends text to the specified file using the specified character encoding. |
| ReadBufferAsync | Reads the contents of the specified file and returns a buffer. |
| ReadLinesAsync(IStorageFile) | Reads the contents of the specified file and returns lines of text. |
| ReadLinesAsync(IStorageFile, UnicodeEncoding) | Reads the contents of the specified file using the specified character encoding and returns lines of text. |
| ReadTextAsync(IStorageFile) | Reads the contents of the specified file and returns text. |
| ReadTextAsync(IStorageFile, UnicodeEncoding) | Reads the contents of the specified file using the specified character encoding and returns text. |
| WriteBufferAsync | Writes data from a buffer to the specified file. |
| WriteBytesAsync | Writes an array of bytes of data to the specified file. |
| WriteLinesAsync(IStorageFile, IIterable(String)) | Writes lines of text to the specified file. |
| WriteLinesAsync(IStorageFile, IIterable(String), UnicodeEncoding) | Writes lines of text to the specified file using the specified character encoding. |
| WriteTextAsync(IStorageFile, String) | Writes text to the specified file. |
| WriteTextAsync(IStorageFile, String, UnicodeEncoding) | Writes text to the specified file using the specified character encoding. |
Remarks
This class is static and cannot be instantiated. Call the methods directly instead.
To learn more about what locations your app can access, see File access and permissions in Windows Store apps.
To learn how to read and write to files, see Quickstart: Reading and writing a file.
Examples
The File Access sample shows you how to use writeTextAsync(file, contents) to write text to a file.
if (file !== null) { Windows.Storage.FileIO.writeTextAsync(file, "Swift as a shadow").done(function () { // Perform additional tasks after file is written }, // 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 write.
Although the writeTextAsync methods don't have a return value, you can still perform additional tasks after the text is written to the file, as the example shows.
The File Access sample also shows you how to use readTextAsync(file) to read text from a file.
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 [Windows Store apps only] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps only] |
|
Namespace |
|
|
Metadata |
|
Build date: 2/25/2013
