Openfile

From OpenEUO
Revision as of 19:22, 7 October 2010 by 76.184.213.234 (Talk) (Created page with " io.open (filename [, mode]) This function opens a file, in the mode specified in the string mode. It returns a new file handle, or, in case of errors, nil plus an error message...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
io.open (filename [, mode])

This function opens a file, in the mode specified in the string mode. It returns a new file handle, or, in case of errors, nil plus an error message.

The mode string can be any of the following:

  • "r": read mode (the default);
  • "w": write mode;
  • "a": append mode;
  • "r+": update mode, all previous data is preserved;
  • "w+": update mode, all previous data is erased;
  • "a+": append update mode, previous data is preserved, writing is only allowed at the end of file.
  • "b": the mode string can also have a 'b' at the end, which is needed to open the file in binary mode.

This string is exactly what is used in the standard C function fopen.