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(
| |
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)
|
|||
Read the contents of a file | |||
Code | <nowiki>
local handler = fs.open("test.txt", "r")
print(handler.readAll())
handler.close()
</nowiki>
|
||
Output | true
|
|
|||
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
|
|
|||
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.