Parameters io.open()

Typically: "How do I... ", "How can I... " questions
Post Reply
need2know
Posts: 13
Joined: 29 Jul 2024, 09:53

Parameters io.open()

Post by need2know »

Hello,

i want to use io.open() to create and edit a text-file. First there should be create a new file in the given path or overwrite an existing one. After i want to continuously add some text to this file.
where can i find an explanation for the second parameter of the function which controlls the behaviour of the file. (r/w/a/w+/a+)

cheers

coppelia
Site Admin
Posts: 10712
Joined: 14 Dec 2012, 00:25

Re: Parameters io.open()

Post by coppelia »

Hello,

The second parameter in io.open() specifies the file mode, which controls how the file is opened and how you can interact with it:
  • "r": Read mode (default). Opens the file for reading. Fails if the file does not exist.
  • "w": Write mode. Creates a new file or overwrites an existing file.
  • "a": Append mode. Opens a file for writing without overwriting existing content.
  • "r+": Read and write mode. The file must exist.
  • "w+": Read and write mode. Creates a new file or overwrites an existing file.
  • "a+": Read and append mode. Opens a file for reading and writing, keeping existing content intact.
Cheers

Post Reply