Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
TA
Talib
OS
os
File
File.close
File.puts
File.printf
File.flush
File.tell
File.seek
File.eof
File.read
File.write
File.getline
File.toString
ListFilesResult
FileStat
Structures
Built-in Variables and Constants
Conventions
Exchanges

Read data from a file.

read()
read(size)

Examples

Read file content in chunks.

javascript
function main() { let file = os.open("data.txt", "r") // data.txt // This is a test line: Line 1. // This is a test line: Line 2. // ... let chunkSize = 29 let totalBytes = 0 while (!file.eof()) { let chunk = file.read(chunkSize) if (chunk) { totalBytes += chunk.length || chunk.byteLength Log("Read chunk, total bytes so far:", totalBytes, ", chunk:", chunk) } } file.close() }

Returns

TypeDescription

string / ArrayBuffer

Returns the content read. At the end of file it returns an empty string "" (an empty ArrayBuffer in b mode).

Arguments

NameTypeRequiredDescription

size

number

No

Number of bytes to read. If not specified, reads all remaining content in the file.

See Also

Remarks

Can read a specified number of bytes or all remaining content in the file. Returns an ArrayBuffer when the file was opened in b mode (e.g. rb), otherwise a string. After reading the rest without a size argument, or after a read that finds no more data, eof() returns true.