Version: v0.8.1 - Beta.  We welcome contributors & feedback.

File.write

$file.write($dataListOrString, $options) -> self

Description

Write the given data to the file.

If the file already exists, it will be overwritten.

If the data is a List, it will be joined by newlines \n.

// Single string
file'files:/data.txt'.write('line1\nline2\nline3')

// List of lines
file'files:/data.txt'.write(['line1', 'line2', 'line3'])

Options

Option Value Description
ifNotExists true/false Do not write the file if it already exists.

This option is useful for restoring missing files to a default state.

file'files:/data.txt'.write($defaultContent, -ifNotExists)

See Also