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

How to make new line at the end of file?

Started by rahph, 28 March 2015 - 03:03 PM
rahph #1
Posted 28 March 2015 - 04:03 PM
So as i told in topic name, how to make new line of text at the end of file? I need small code.
MKlegoman357 #2
Posted 28 March 2015 - 04:34 PM
Use the new line character '\n' or use the file.writeLine function, which appends that character automatically.
GopherAtl #3
Posted 28 March 2015 - 08:29 PM
note file.writeLine adds a \n to the end, just like print() does, so if you're appending text to an existing log that doesn't have a newline at the end, you'll want to put a '\n' at the start of your string instead. Or just manually repair or reset the log files and always use writeLine instead of write.
valithor #4
Posted 28 March 2015 - 09:35 PM
I am assuming he is talking more about how if you open a file in write mode using fs.open it will erase the contents of the file. So building on what the other people have said you would want to do something like this.


handle = fs.open("file","a") -- "a" stands for append it will add it to the end of the file instead of erasing the file
handle.writeLine("Whatever you want to write here.")
handle.close() -- if you dont close the file it will not save, and other problems could occur.
Edited on 28 March 2015 - 08:37 PM