Skip to content

datasource.writeFile ^v2.7.191 ​

Writes text or bytes to a file. Missing folders in the path are created.

js
datasource.writeFile(fileName, data, append)

Parameters ​

ParameterTypeDescription
fileNamestringThe path of the file.
datastring | number[]The text to write, written as UTF-8, or an array of byte values from 0 to 255.
appendbooleanOptional. true to add to the end of the file instead of replacing it. Defaults to false.

Returns ​

boolean

true when the file was written, or false when the path is invalid.

Examples ​

js
// Write text to a new file
datasource.writeFile("output/report.txt", "Hello, World!");

// Append text to an existing file
datasource.writeFile("output/log.txt", "New log entry\n", true);

// Write binary data as an array of integers
const bytes = [72, 101, 108, 108, 111]; // "Hello" in ASCII
datasource.writeFile("output/data.bin", bytes);

// Write JSON data
const data = {
    name: "Budget Report",
    year: 2024,
    values: [100, 200, 300]
};
datasource.writeFile("output/report.json", JSON.stringify(data, null, 2));