View source code
Display the source code in std/file.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.file.readText
Reads and validates (using 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, R)
(
auto ref R name
)
if (isSomeString!S && (isSomeFiniteCharInputRange!R || is(StringTypeOf!R)));
Parameters
Name | Description |
---|---|
S | the string type of the file |
name | string or range of characters representing the file name |
Returns
Array of characters read.
Throws
FileException
if there is an error reading the file,
UTFException
on UTF decoding error.
Example
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);
writeln(content); // "abc"
Authors
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.