Skip to content

kiwi.io.FileWriter

Nikos Siatras edited this page Sep 22, 2022 · 6 revisions

The FileWriter writes text to character files using a default buffer size. Encoding from characters to bytes uses either a specified charset or the FreeBasic's default charset (Ascii).

The FileWriter class exists in the kiwi/io/FileWriter.bi file.

FileWriter Class Methods

Method Description
FileReader.write() Writes a string to the output file
FileReader.append() Appends a string to the end of the output file
FileReader.getEncoding() Returns the name of the character encoding being used by this stream.

FileWriter Examples

Example - Write and Append to a Text File

#include once "kiwi\kiwi.bi"
#include once "kiwi\io.bi" ' Include Kiwi's IO package

' Initialize a File and a FileWriter
Dim myFile as File = File("C:\Users\nsiat\Desktop\Test.txt")
Dim myWriter as FileWriter = FileWriter(myFile, Charset.UTF8) ' Using UTF-8 Charset

' The fist line will be written to the text file
myWriter.write("Hello!" & System.lineSeparator) 

' The next 3 lines will be appended
myWriter.append("This is simple Text file" & System.lineSeparator) 
myWriter.append("created by Kiwi Framework" & System.lineSeparator)
myWriter.append("for FreeBasic :)" & System.lineSeparator)