readText

Reads and validates (using std.utf.validate) a text file. S can be an array of any character type. However, no width or endian conversions are performed. So, if the width or endianness of the characters in the given file differ from the width or endianness of the element type of S, then validation will fail.

S
readText
(
S = string
R
)
(
auto ref R name
)
if (
(
is(StringTypeOf!R)
)
)

Parameters

S

the string type of the file

name R

string or range of characters representing the file name

Return Value

Type: S

Array of characters read.

Throws

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

Examples

Read file with UTF-8 text.

write(deleteme, "abc"); // deleteme is the name of a temporary file
scope(exit) remove(deleteme);
string content = readText(deleteme);
assert(content == "abc");

See Also

std.file.read for reading a binary file.

Meta