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

[Question] Just a Weird Quirk I Noticed with Floppy Disks

Started by Rotaretilbo, 27 July 2012 - 11:44 AM
Rotaretilbo #1
Posted 27 July 2012 - 01:44 PM
So I've been working on a program that allows a user to send news from a remote console to update a large monitor display in the town hall of a town I live near in a particular server. With the help of several forummers here, I've managed to resolve all of the coding issues I was experiencing during this process. There is, however, one question that remains in my mind.

The setup that I'm using uses three computers and a disk drive. The remote console sending the news updates sends messages over rednet to a second computer, which is in a while true do loop to listen for messages. The listener computer then writes these messages to a blank file on a floppy disk in an adjacent disk drive, and the third computer, also adjacent to the disk drive, then grabs info from that file to display on the monitor. The program works wonderfully, and I'm quite pleased.

However, I've noticed that every time I open the file in which the data is stored (henceforth referred to as /disk/logs), after saving and exiting, it adds a blank space to the bottom of the file. For example, if the contents of the file were as follows:

Test 1
Test 2
Test #

And I opened it up manually because the # was a typo and should be a 3, then saved it and promptly sent a new news update, "Test 4" from the remote console and then "Test 5" immediately thereafter, it would look like this:

Test 1
Test 2
Test 3

Test 4
Test 5

And if I opened it up manually and deleted that annoying blank line and repeated the process, we'd have:

Test 1
Test 2
Test 3
Test 4
Test 5

Test 6
Test 7

Now, code-wise, I worked around this by having the program in the third computer ignore lines equal to "" when grabbing the file contents, but I'm curious as to whether or not anyone knows why this is, and if there is a way to prevent it.
MysticT #2
Posted 27 July 2012 - 03:25 PM
The edit program adds a new line at the end of the file. If your program adds one to the end before writing, that's the problem. You should use file.writeLine each time you write a line and don't add the new line yourself.