This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
mrhappy5354's profile picture

Refresh all files in computer ?

Started by mrhappy5354, 17 January 2015 - 05:35 AM
mrhappy5354 #1
Posted 17 January 2015 - 06:35 AM
When I simply open and write in a text file:

u = fs.open("Hello", "w")
u.write("Hello")

and then I edit the file nothing is written in it, the text will only appear after I reboot the computer…

So is there a fix, because this is really annoying…

Thanks
Lyqyd #2
Posted 17 January 2015 - 10:14 AM
You're supposed to close file handles after you're done using them. Throw this after the write call:


u.close()

That will close the file handle and write your changes to the actual file.
ElvishJerricco #3
Posted 17 January 2015 - 11:51 AM
Also, flushing writes unwritten data to disk. Closing says "I'm done, I have no more to write. Put all my changes on disk and clean up now." This is required. But flushing just puts the changes on disk, without doing the closing, so that you can continue to write to the file after flushing.


u.writeLine("Hello")
u.flush()
u.writeLine("Hello again")

The resulting file will only have the "Hello" line, because that line was flushed, and the second line was not, since the handle was never closed or flushed after its writeLine call.
mrhappy5354 #4
Posted 17 January 2015 - 07:30 PM
Thanks a lot for the quick respond !