Built-in Functions
Structures
Built-in Variables and Constants
Conventions
Exchanges
File.puts
Write one or more strings to a file.
puts(data1, data2, ...dataN)Examples
Write multiple strings to a file.
javascript
function main() {
let file = os.open("output.txt", "w+")
let bytes = file.puts("Hello", " ", "World", "!")
Log("Bytes written:", bytes)
// Output: Bytes written: 12
file.seek(0, 0)
let data = file.read()
Log("data:", data)
// Output: data: Hello World!
// If the file is opened with os.open("output.txt", "w") (write-only), read() throws
// file.puts() // error: puts requires at least 1 argument at main
file.puts(", Hello FMZ!")
file.seek(0, 0)
data = file.read()
Log("data:", data)
// Output: data: Hello World!, Hello FMZ!
file.close()
}Returns
| Type | Description |
number | Returns the actual number of bytes written. |
Arguments
| Name | Type | Required | Description |
data | string | Yes | String data to be written, multiple parameters can be passed. |
See Also
Remarks
Multiple string parameters can be written at once, they will be concatenated in order and then written.