Code: Select all
f$="ram:test.txt"
; This writes to the middle of the file as supposed
StringToFile("abcdefg", f$)
f=OpenFile(Nil, f$, #MODE_READWRITE)
Seek(f, 3)
WriteString(f, "0")
CloseFile(f)
DebugPrint(FileToString(f$))
; Why this appends to the end and doesn't write to the middle of the file?
StringToFile("abcdefg", f$)
f=OpenFile(Nil, f$, #MODE_READWRITE)
ReadString(f, 1)
Seek(f, 3)
WriteString(f, "0")
CloseFile(f)
DebugPrint(FileToString(f$))
abc0efg 7
abcdefg0 8
While on Windows it is:
abc0efg 7
abc0efg 7
I tried to replicate this on plain Lua on MorphOS, and there it prints just like on Windows, so it seems it's Hollywood which doesn't do it right for some reason.
A workaround for this is to open a file, read it and store information you need, close file, re-open it and write then what you need...