loadTextFile: Difference between revisions

co
No edit summary
(co)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{ScriptItem
{{ScriptItem
|since = 1.2.1 1.2.1
|endpoint = shared
|endpoint = shared
|type = function
|type = function
Line 6: Line 7:
|parameter1 = string filePath The path to the file.
|parameter1 = string filePath The path to the file.
|returnTypes = string
|returnTypes = string
|usage = fetch all text inside a file.<br>The file and text returned may contain new-line character(s).<br>The text fetched is either up to the EOF (end of file) or first null-byte (\0) character, whichever occurs first.<br>This function internally opens, reads, and closes the file.<br>The file is internally opened in text-mode, not binary-mode.<br>The file is internally opened in read-mode, not write-mode.
|usage = fetch all text inside a file as a string, or null if there was a failure
|returnInfo = the text fetched, as a string, which could be an empty string
|returnInfo = the text fetched, as a string, which could be an empty string if the file is blank, or null if a failure occurred (e.g. if the file was not found, or the file can't be opened)
|returnFail1 = null n/a
|returnFail1 = null n/a
|example = <code>
let data = loadTextFile(filePath);
if(data === null)
console.log('Failed to load text file.');
else
console.log('File data: '+data);
</code>
}}
}}
6,833

edits