Exemplo n.º 1
0
    public static async Task WriteText(string filePath, string text)
    {
        var encodedText = Utf8NoBOM.GetBytes(text);

        using var fileStream = OpenWrite(filePath);
        await fileStream.WriteAsync(encodedText, 0, encodedText.Length);
    }
Exemplo n.º 2
0
    public static async Task <string> ReadText(string filePath)
    {
        using var stream = OpenRead(filePath);
        var builder = new StringBuilder();

        var buffer = new byte[0x1000];
        int numRead;

        while ((numRead = await stream.ReadAsync(buffer, 0, buffer.Length)) != 0)
        {
            var text = Utf8NoBOM.GetString(buffer, 0, numRead);
            builder.Append(text);
        }

        return(builder.ToString());
    }