Functions -
io
createReadableChannel |
Creates an in-memory channel, which will be a reference stream of bytes. |
openReadableCsvFile |
Retrieves a readable CSV channel from a given file path. |
openReadableFile |
Retrieves a |
openWritableCsvFile |
Retrieves a writable CSV channel from a given file path. |
openWritableFile |
Retrieves a |
Prints |
|
println |
Prints |
readln |
Retrieves the input read from the STDIN. |
sprintf |
Returns a formatted string using the specified format string and arguments. |
Creates an in-memory channel, which will be a reference stream of bytes.
var byteChannel = io:createReadableChannel(content);
Parameters
- content byte[]
-
Content, which should be exposed as a channel
-
Return Type
(ReadableByteChannel | Error) The
ByteChannel
representation to read the memory content or else anio:Error
if any error occurred
openReadableCsvFile
(string path, Separator fieldSeparator, string charset, int skipHeaders)
returns ReadableCSVChannel | ErrorRetrieves a readable CSV channel from a given file path.
io:ReadableCSVChannel rCsvChannel = check io:openReadableCsvFile(srcFileName);
Parameters
- path string
-
File path, which describes the location of the CSV
- fieldSeparator Separator (default ,)
-
CSV record separator (i.e., comma or tab)
- charset string (default UTF-8)
-
Representation of the encoding characters in the file
- skipHeaders int (default 0)
-
Number of headers, which should be skipped
-
Return Type
(ReadableCSVChannel | Error) The
ReadableCSVChannel
, which could be used to iterate through the CSV records or else anio:Error
if any error occurred.
Retrieves a ReadableByteChannel
from a given file path.
io:ReadableByteChannel readableFieldResult = check io:openReadableFile("./files/sample.txt");
Parameters
- path string
-
Relative/absolute path string to locate the file
-
Return Type
(ReadableByteChannel | Error) The
ByteChannel
representation of the file resource or else anio:Error
if any error occurred
openWritableCsvFile
(string path, Separator fieldSeparator, string charset, int skipHeaders)
returns WritableCSVChannel | ErrorRetrieves a writable CSV channel from a given file path.
io:WritableCSVChannel wCsvChannel = check io:openWritableCsvFile(srcFileName);
Parameters
- path string
-
File path, which describes the location of the CSV
- fieldSeparator Separator (default ,)
-
CSV record separator (i.e., comma or tab)
- charset string (default UTF-8)
-
Representation of the encoding characters in the file
- skipHeaders int (default 0)
-
Number of headers, which should be skipped
-
Return Type
(WritableCSVChannel | Error) The
WritableCSVChannel
, which could be used to write the CSV records or else anio:Error
if any error occurred
Retrieves a WritableByteChannel
from a given file path.
io:WritableByteChannel writableFileResult = check io:openWritableFile("./files/sampleResponse.txt");
Parameters
- path string
-
Relative/absolute path string to locate the file
- append boolean (default false)
-
Whether to append to the end of file
-
Return Type
(WritableByteChannel | Error) The
ByteChannel
representation of the file resource or else anio:Error
if any error occurred
Prints any
or error
value(s) to the STDOUT.
io:print("Start processing the CSV file from ", srcFileName);
Parameters
- values any | error[]
-
The value(s) to be printed.
Prints any
or error
value(s) to the STDOUT followed by a new line.
io:println("Start processing the CSV file from ", srcFileName);
Parameters
- values any | error[]
-
The value(s) to be printed.
Retrieves the input read from the STDIN.
string choice = io:readln("Enter choice 1 - 5: ");
Parameters
- a any
-
Any value to be printed
-
Return Type
(string) Input read from the STDIN
Returns a formatted string using the specified format string and arguments. Following format specifiers are allowed.
b - boolean
B - boolean (ALL_CAPS)
d - int
f - float
x - hex
X - HEX (ALL_CAPS)
s - string (This specifier is applicable for any of the supported types in Ballerina. These values will be converted to their string representation.)
string s8 = io:sprintf("%s scored %d for %s and has an average of %.2f.", name, marks, subjects[0], average);
Parameters
- format string
-
A format string
- args any | error[]
-
Arguments referred by the format specifiers in the format string
-
Return Type
(string) The formatted string