Path.readFileText

Read text content of the file. Technicall just a call to std.file.readText.

struct Path
const
readFileText
(
S = string
)
()

Parameters

S

template parameter that represents type of string to read

Return Value

Type: auto

text read from file.

Throws

FileException if there is an error reading the file, std.utf.UTFException on UTF decoding error.

Examples

import dshould;
Path root = createTempPath();
scope(exit) root.remove();

// Write some utf-8 data from the file
root.join("test-utf-8.txt").writeFile("Hello World");

// Test that we read correct value
root.join("test-utf-8.txt").readFileText.should.equal("Hello World");

// Write some data in UTF-16 with BOM
root.join("test-utf-16.txt").writeFile("\uFEFFhi humans"w);

// Read utf-16 content
auto content = root.join("test-utf-16.txt").readFileText!wstring;

// Strip BOM if present.
import std.algorithm.searching : skipOver;
content.skipOver('\uFEFF');

// Ensure we read correct value
content.should.equal("hi humans"w);

Meta