This is documentation for Mathematica 7, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

BinaryWrite

BinaryWrite[channel, b]
writes a byte of data, specified as an integer from 0 to 255.
BinaryWrite[channel, {b1, b2, ...}]
writes a sequence of bytes.
BinaryWrite[channel, "string"]
writes the raw sequence of characters in a string.
BinaryWrite[channel, x, type]
writes an object of the specified type.
BinaryWrite[channel, {x1, x2, ...}, type]
writes a sequence of objects of the specified type.
BinaryWrite[channel, {x1, x2, ...}, {type1, type2, ...}]
writes a sequence of objects with a sequence of types.
  • The output channel used by BinaryWrite can be a single file or pipe, or a list of them, each specified by a string giving its name, or by an OutputStream object that has been opened with BinaryFormat->True.
  • If any of the specified files or pipes are not already open, BinaryWrite calls OpenWrite to open them.
  • BinaryWrite does not close files and pipes after it finishes writing to them.
  • When a list of types is given, the list is effectively repeated as many times as necessary.
  • The following options can be given:
ByteOrdering$ByteOrderingwhat byte ordering to use
  • BinaryWrite[channel, "string"] uses type "Character8", so all characters in "string" should have character codes in the range 0-255.
  • BinaryWrite returns $Failed if it encounters a data element that cannot match the type specified.
Create a file with a sequence of bytes:
Close the stream:
Read the first byte from the file:
Close the stream:
Create a file with a sequence of bytes:
In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Close the stream:
In[3]:=
Click for copyable input
Read the first byte from the file:
In[4]:=
Click for copyable input
Out[4]=
In[5]:=
Click for copyable input
Out[5]=
In[6]:=
Click for copyable input
Out[6]=
Close the stream:
In[7]:=
Click for copyable input
New in 5.1