os.fputs
Write content to a file.
fputs(filename, content)
fputs(filename, content, append)Examples
Save strategy configuration to file.
javascript
function main() {
let config = '{"strategy": "MA", "period": 20}'
let bytesWritten = os.fputs("strategy_config.json", config)
Log("Bytes written:", bytesWritten)
// Output: Bytes written: 32
Log(`os.fgets("strategy_config.json"):`, os.fgets("strategy_config.json"))
// Output: os.fgets("strategy_config.json"): {"strategy": "MA", "period": 20}
// append a log line
let logInfo = "\n[" + new Date().toISOString() + "] Config saved"
os.fputs("strategy_config.json", logInfo, true)
Log(`os.fgets("strategy_config.json"):`, os.fgets("strategy_config.json"))
// Output: os.fgets("strategy_config.json"): {"strategy": "MA", "period": 20}
// [2025-09-08T07:20:30.563Z] Config saved
}Returns
| Type | Description |
number | Returns the actual number of bytes written. |
Arguments
| Name | Type | Required | Description |
filename | string | Yes | File path. |
content | string | Yes | Content to write. |
append | bool | No | Whether to write in append mode, defaults to false (overwrite mode). |
See Also
Remarks
Convenient file writing method, overwrites file content by default. Set append to true to append to the end of the file.