Wheel IDE

Online demo »

File, write

File write example

This example shows how to create a file with meta commands and read strings and numbers from the file.

When you run this example then a file named furniture.rtf will be written in the examples/file/output.

Code

#project "File write example"

#include "lib/modules/standard.whl"
#include "lib/modules/file.whl"

proc main()
    if fileExists("furniture.rtf")
        printS("The file exists and has a size of:")
        printN(fileSize("furniture.rtf"))
        printS("bytes")
        fileDelete("furniture.rtf")
    end
    number handle = fileOpenWrite("furniture.rtf")
    fileWriteNumber(handle, 1)
    fileWriteString(handle, "Chair")
    fileWriteNumber(handle, 2)
    fileWriteString(handle, "Table")
    fileWriteNumber(handle, 3)
    fileWriteString(handle, "Cupboard")
end