Build a File-Driven Integration
Time: Under 10 minutes | What you'll build: A file integration that adds an onModify handler to track file changes and uses printInfo to log file modification events.
File integrations are ideal for batch uploads, scheduled file processing, and ETL workflows triggered by files appearing in a folder or FTP server.
-
A file at the listener path to watch. Create one if you don't have one:
- macOS / Linux
- Windows
echo "test" > /tmp/testfile.txtmkdir C:\tmp 2>nul
echo test > C:\tmp\testfile.txt
- Visual Designer
- Ballerina Code
Step 1: Create the project
- Open WSO2 Integrator.
- Select the Create New Integration card.
- Set Integration Name to
FileTracker. - Set Project Name to
file-integration. - Select Create Integration.


Step 2: Add a file integration artifact
- Select FileTracker from Project Overview Canvas.
- In the design view, select + Add Artifact.
- Select Local Files under File Integration.
- Set Path to
/tmp(macOS/Linux) orC:\tmp(Windows). Select Create.


Step 3: Add onModify event handler
- In the service designer view, select + Add Handler.
- Select onModify.


Step 4: Add file tracking logic
- Select + in the flow diagram.
- Search for
printInfoand select printInfo. - Set Msg to
File modifiedand select Save.
Step 5: Run and test
-
Select Run in the toolbar.
-
Run the modify command in your terminal to trigger the handler:
- macOS / Linux
- Windows
echo "modify" > /tmp/testfile.txtecho modify > C:\tmp\testfile.txt -
Confirm the run terminal shows the log line
File modified.


The following complete, runnable Ballerina program produces the same integration shown in the visual designer steps.
Change the listener path from "/tmp" to "C:\\tmp" (backslash escaped) before running the program.
import ballerina/file;
import ballerina/log;
listener file:Listener fileListener = new (path = "/tmp", recursive = false);
service file:Service on fileListener {
remote function onModify(file:FileEvent event) returns error? {
do {
log:printInfo("File modified");
} on fail error err {
// handle error
return error("unhandled error", err);
}
}
}
Save this as main.bal, then run bal run from the project directory. With the test file already in place (see Prerequisites), run the modify command in a separate terminal to trigger the handler:
- macOS / Linux
- Windows
echo "modify" > /tmp/testfile.txt
echo modify > C:\tmp\testfile.txt
Confirm the run terminal shows the log line File modified.
What's next
- Local files — Full Local Files listener reference (events, recursive watching, file handlers)
- FTP/SFTP — Watch and process files on remote FTP or SFTP servers
- Streaming large files — Process large files without loading them fully into memory
- CSV fault tolerance — Handle errors and partial failures when processing CSV files