read

Read entire contents of file name and returns it as an untyped array. If the file size is larger than upTo, only upTo bytes are read.

  1. void[] read(R name, size_t upTo)
    void[]
    read
    (
    R
    )
    (,
    size_t upTo = size_t.max
    )
  2. void[] read(R name, size_t upTo)

Parameters

name R

string or range of characters representing the file name

upTo size_t

if present, the maximum number of bytes to read

Return Value

Type: void[]

Untyped array of bytes read.

Throws

FileException on error.

Examples

import std.utf : byChar;
scope(exit)
{
    assert(exists(deleteme));
    remove(deleteme);
}

std.file.write(deleteme, "1234"); // deleteme is the name of a temporary file
assert(read(deleteme, 2) == "12");
assert(read(deleteme.byChar) == "1234");
assert((cast(const(ubyte)[])read(deleteme)).length == 4);

See Also

std.file.readText for reading and validating a text file.

Meta