fs.open

Opens a file for reading, writing, or appending. Writing to a file that does not exist creates the file.

fs.open
Function
Syntax
fs.open(
  • Path : string
  • Mode : char
)

Returns Input Handler (w/a) Output Handler (r)
API fs
Source CC:Tweaked (source)

Mode Must be either w (writing), a (appending), or r (reading)

ExampleRead A File
Read the contents of a file
Code
<nowiki>
local handler = fs.open("test.txt", "r")
print(handler.readAll())
handler.close()
    </nowiki>
Output
true
ExampleAppend to A File
Append text to the contents of a file
Code
<nowiki>
local handler = fs.open("test.txt", "a")
handler.write(World!”)
handler.close()
    </nowiki>
Output
true
ExampleWrite to A File
Override the contents of a file
Code
<nowiki>
local handler = fs.open("test.txt", "w")
handler.write("Hello World!")
handler.close()
    </nowiki>
Output
true
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.