write

Write buffer to file name.

Creates the file if it does not already exist.

  1. void write(R name, void[] buffer)
  2. void write(R name, void[] buffer)
    void
    write
    (
    R
    )
    (
    auto ref R name
    ,
    const void[] buffer
    )

Parameters

name R

string or range of characters representing the file name

buffer void[]

data to be written to file

Throws

FileException on error.

Examples

scope(exit)
{
    assert(exists(deleteme));
    remove(deleteme);
}

int[] a = [ 0, 1, 1, 2, 3, 5, 8 ];
write(deleteme, a); // deleteme is the name of a temporary file
const bytes = read(deleteme);
const fileInts = () @trusted { return cast(int[]) bytes; }();
assert(fileInts == a);

See Also

Meta