This I/O library provides file read/write APIs and console print/read APIs. The file APIs allow read and write operations on different kinds of file types such as bytes, text, CSV, JSON, and XML. Further, these file APIs can be categorized as streaming and non-streaming APIs.
The following diagram depicts the overview architecture of the I/O package.
The file I/O operations can be categorized further based on the serialization and deserialization types such as:
- Bytes I/O
- Strings I/O
- CSV I/O
- JSON I/O
- XML I/O
The console I/O APIs, which help you to read from the console as well as write to the console are as follows.
io:print
io:println
io:readln
The bytes I/O APIs provide the reading and writing APIs in both streaming and non-streaming ways. Those APIs are,
io:fileReadBytes
io:fileReadBlocksAsStream
io:fileWriteBytes
io:fileWriteBlocksFromStream
The strings I/O APIs provide the reading and writing APIs in 3 different ways:
- Read the complete file content as a string and write a given string to a file
- Read the complete file content as a set of lines and write a given set of lines to a file
- Read the complete file content as a stream of lines and write a given stream of lines to a file
The strings I/O APIs are as follows:
io:fileReadString
io:fileReadLines
io:fileReadLinesAsStream
io:fileWriteLines
io:fileWriteLinesFromStream
The CSV I/O APIs provide the reading and writing APIs in both streaming and non-streaming ways. Those APIs are:
io:fileReadCsv
io:fileReadCsvAsStream
io:fileWriteCsv
io:fileWriteCsvFromStream
The JSON I/O APIs provide the reading and writing APIs for JSON content. Those APIs are:
io:fileReadJson
io:fileWriteJson
The XML I/O APIs provide the reading and writing APIs for XML content. Those APIs are:
io:fileReadXml
io:fileWriteXml
Issues and Projects tabs are disabled for this repository as this is part of the Ballerina Standard Library. To report bugs, request new features, start new discussions, view project boards, etc. please visit Ballerina Standard Library parent repository.
This repository only contains the source code for the module.
-
Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations).
-
Export Github Personal access token with read package permissions as follows,
export packageUser=<Username> export packagePAT=<Personal access token>
Execute the commands below to build from source.
-
To build the library:
./gradlew clean build
-
To run the integration tests:
./gradlew clean test
-
To build the module without the tests:
./gradlew clean build -x test
-
To debug module implementation:
./gradlew clean build -Pdebug=<port> ./gradlew clean test -Pdebug=<port>
-
To debug the module with Ballerina language:
./gradlew clean build -PbalJavaDebug=<port> ./gradlew clean test -PbalJavaDebug=<port>
-
Publish ZIP artifact to the local
.m2
repository:./gradlew clean build publishToMavenLocal
-
Publish the generated artifacts to the local Ballerina central repository:
./gradlew clean build -PpublishToLocalCentral=true
-
Publish the generated artifacts to the Ballerina central repository:
./gradlew clean build -PpublishToCentral=true
As an open source project, Ballerina welcomes contributions from the community.
For more information, go to the contribution guidelines.
All contributors are encouraged to read the Ballerina Code of Conduct.
- Chat live with us via our Discord server.
- Post all technical questions on Stack Overflow with the #ballerina tag.
- For more information go to the I/O Package.
- For example demonstrations of the usage, go to Ballerina By Examples.