fs.open

From ComputerCraft
Jump to navigation Jump to search

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

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

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

ExampleExampleRead A File
Read the contents of a file
Code
local handler = fs.open("test.txt", "r")
print(handler.readAll())
handler.close()
Output
true
ExampleExampleAppend to A File
Append text to the contents of a file
Code
local handler = fs.open("test.txt", "a")
handler.write(“World!”)
handler.close()
Output
true
ExampleExampleWrite to A File
Override the contents of a file
Code
local handler = fs.open("test.txt", "w")
handler.write("Hello World!")
handler.close()
Output
true