FileIO FileIO FileIO FileIO FileIO Class

Definition

Provides helper methods for reading and writing files that are represented by objects of type IStorageFile.

public : static class FileIO
static struct winrt::Windows::Storage::FileIO
public static class FileIO
Public Static Class FileIO
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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
    });
}
try
{
    if (file != null)
    {
        await FileIO.WriteTextAsync(file, "Swift as a shadow");
    }
}
// Handle errors with catch blocks
catch (FileNotFoundException)
{
    // For example, handle file not found
}

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
    });
}
try
{
    if (file != null)
    {
        string fileContent = await FileIO.ReadTextAsync(file);
    }
}
// Handle errors with catch blocks
catch (FileNotFoundException)
{
    // For example, handle file not found
}

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.

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 permissions.

To learn how to read and write to files, see Create, write, and read a file.

Methods

AppendLinesAsync(IStorageFile, IIterable<String>) AppendLinesAsync(IStorageFile, IIterable<String>) AppendLinesAsync(IStorageFile, IIterable<String>) AppendLinesAsync(IStorageFile, IIterable<String>) AppendLinesAsync(IStorageFile, IIterable<String>)

Appends lines of text to the specified file.

AppendLinesAsync(IStorageFile, IIterable<String>, UnicodeEncoding) AppendLinesAsync(IStorageFile, IIterable<String>, UnicodeEncoding) AppendLinesAsync(IStorageFile, IIterable<String>, UnicodeEncoding) AppendLinesAsync(IStorageFile, IIterable<String>, UnicodeEncoding) AppendLinesAsync(IStorageFile, IIterable<String>, UnicodeEncoding)

Appends lines of text to the specified file using the specified character encoding.

AppendTextAsync(IStorageFile, String) AppendTextAsync(IStorageFile, String) AppendTextAsync(IStorageFile, String) AppendTextAsync(IStorageFile, String) AppendTextAsync(IStorageFile, String)

Appends text to the specified file.

AppendTextAsync(IStorageFile, String, UnicodeEncoding) AppendTextAsync(IStorageFile, String, UnicodeEncoding) AppendTextAsync(IStorageFile, String, UnicodeEncoding) AppendTextAsync(IStorageFile, String, UnicodeEncoding) AppendTextAsync(IStorageFile, String, UnicodeEncoding)

Appends text to the specified file using the specified character encoding.

ReadBufferAsync(IStorageFile) ReadBufferAsync(IStorageFile) ReadBufferAsync(IStorageFile) ReadBufferAsync(IStorageFile) ReadBufferAsync(IStorageFile)

Reads the contents of the specified file and returns a buffer.

ReadLinesAsync(IStorageFile) ReadLinesAsync(IStorageFile) ReadLinesAsync(IStorageFile) ReadLinesAsync(IStorageFile) ReadLinesAsync(IStorageFile)

Reads the contents of the specified file and returns lines of text.

ReadLinesAsync(IStorageFile, UnicodeEncoding) ReadLinesAsync(IStorageFile, UnicodeEncoding) ReadLinesAsync(IStorageFile, UnicodeEncoding) ReadLinesAsync(IStorageFile, UnicodeEncoding) ReadLinesAsync(IStorageFile, UnicodeEncoding)

Reads the contents of the specified file using the specified character encoding and returns lines of text.

ReadTextAsync(IStorageFile) ReadTextAsync(IStorageFile) ReadTextAsync(IStorageFile) ReadTextAsync(IStorageFile) ReadTextAsync(IStorageFile)

Reads the contents of the specified file and returns text.

ReadTextAsync(IStorageFile, UnicodeEncoding) ReadTextAsync(IStorageFile, UnicodeEncoding) ReadTextAsync(IStorageFile, UnicodeEncoding) ReadTextAsync(IStorageFile, UnicodeEncoding) ReadTextAsync(IStorageFile, UnicodeEncoding)

Reads the contents of the specified file using the specified character encoding and returns text.

WriteBufferAsync(IStorageFile, IBuffer) WriteBufferAsync(IStorageFile, IBuffer) WriteBufferAsync(IStorageFile, IBuffer) WriteBufferAsync(IStorageFile, IBuffer) WriteBufferAsync(IStorageFile, IBuffer)

Writes data from a buffer to the specified file.

WriteBytesAsync(IStorageFile, Byte[]) WriteBytesAsync(IStorageFile, Byte[]) WriteBytesAsync(IStorageFile, Byte[]) WriteBytesAsync(IStorageFile, Byte[]) WriteBytesAsync(IStorageFile, Byte[])

Writes an array of bytes of data to the specified file.

WriteLinesAsync(IStorageFile, IIterable<String>) WriteLinesAsync(IStorageFile, IIterable<String>) WriteLinesAsync(IStorageFile, IIterable<String>) WriteLinesAsync(IStorageFile, IIterable<String>) WriteLinesAsync(IStorageFile, IIterable<String>)

Writes lines of text to the specified file.

WriteLinesAsync(IStorageFile, IIterable<String>, UnicodeEncoding) WriteLinesAsync(IStorageFile, IIterable<String>, UnicodeEncoding) WriteLinesAsync(IStorageFile, IIterable<String>, UnicodeEncoding) WriteLinesAsync(IStorageFile, IIterable<String>, UnicodeEncoding) WriteLinesAsync(IStorageFile, IIterable<String>, UnicodeEncoding)

Writes lines of text to the specified file using the specified character encoding.

WriteTextAsync(IStorageFile, String) WriteTextAsync(IStorageFile, String) WriteTextAsync(IStorageFile, String) WriteTextAsync(IStorageFile, String) WriteTextAsync(IStorageFile, String)

Writes text to the specified file.

WriteTextAsync(IStorageFile, String, UnicodeEncoding) WriteTextAsync(IStorageFile, String, UnicodeEncoding) WriteTextAsync(IStorageFile, String, UnicodeEncoding) WriteTextAsync(IStorageFile, String, UnicodeEncoding) WriteTextAsync(IStorageFile, String, UnicodeEncoding)

Writes text to the specified file using the specified character encoding.