updating oE write_file


include io.e 
namespace io 
public function write_file(object file, sequence data, integer as_text = BINARY_MODE) 

write a sequence of bytes to a file.

  1. file : an object, either a file path or the handle to an open file.
  2. data : the sequence of bytes to write
  3. as_text : integer
    • BINARY_MODE (the default) assumes binary mode that causes every byte to be written out as is,
    • TEXT_MODE assumes text mode that causes a NewLine to be written out according to the operating system's end of line convention. On Unix this is Control+J and on Windows this is the pair {Ctrl-L, Ctrl-J}.
    • UNIX_TEXT ensures that lines are written out with Unix style line endings (Control+J).
    • DOS_TEXT ensures that lines are written out with Windows style line endings {Ctrl-L, Ctrl-J}.

An integer, 1 on success, -1 on failure.


If puts cannot write data, a runtime error will occur.

  • When file is a file handle, the file is not closed after writing is finished. When file is a file name, it is opened, written to and then closed.
  • Note that when writing the file in ony of the text modes, the file is truncated at the first Control+Z character in the input data.
Example 1:
if write_file("data.txt", "This is important data\nGoodbye") = -1 then 
    puts(STDERR, "Failed to write data\n") 
end if 
See Also:

read_file, write_lines

Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu