NAME

write - write binary values to a file

SYNOPSIS

file.write(val, ...)

DESCRIPTION

The write() intrinsic method is used for binary-mode file unformatted writes.

Unformatted binary-mode writes do not use a format specifier. Rather, they rely on the type of the arguments passed in to determine what to write. Each argument may be a of an elemental scalar type (for example, Int, Float, etc.) or a packed array type (for example, String[40] or PackInt[1024]). From one to eight unsigned bytes are optionally byte-swapped and then written to the output file, according to this table:

Base Type Bytes Byte swap
Bool, Char,
Byte, Ubyte
1 n/a
Short, Ushort,
Half
2 AB -> BA
WideChar, Int,
Uint, Float
4 ABCD -> DCBA
Long, Ulong,
Double
8 ABCDEFGH -> HGFEDCBA

See setswab and getswab for more information on byte swapping.

RETURN VALUE

None

ERRORS

ArgCheck for an incorrect number of arguments
TypeCheck for a non-elemental val
AccessCheck for an attempt to access a closed file
IoCheck for other miscellaneous I/O errors (see ferror)

EXAMPLE

    // Write an Int in native byte order and then swapped byte order
    // to an output file
    file.write(42);
    file.setswab(true);
    file.write(42);

SEE ALSO

read
getswab
setswab
isbinary
ferror
new File