View source code
Display the source code in std/file.d from which this page was generated on
github.
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.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.file.readText
Read and validates (using std.utf.validate
) a text file. S
can be a type of array of characters of any width and constancy. No
width conversion is performed; if the width of the characters in file
is different from the width of elements of name
S
,
validation will fail.
Prototype
S readText(S, R)( R name ) if (isSomeString!S && (isInputRange!R && isSomeChar!(ElementEncodingType!R) || isSomeString!R));
Parameters
Name | Description |
---|---|
name | string or range of characters representing the file name |
Returns
Array of characters read
.
Throws
on file error, FileException
UTFException
on UTF
decoding error.
Example
import std.string; write("someUniqueFilename", "abc\n"); scope(exit) { assert(exists("someUniqueFilename")); remove("someUniqueFilename"); } enforce(chomp(readText("someUniqueFilename")) == "abc");
Authors
Walter Bright, Andrei Alexandrescu, Jonathan M Davis