Skip to content

$ps.file.readAllText

Overview

This function is used in "Server Script" to read files using "$ps.file" It reads the entire content of a file and returns the value as a string.

Prerequisites

The DisableServerScriptFile setting in Script.json must be set to false.

Syntax

$ps.file.readAllText(section, path, encode=null);

Parameters

Parameters Type Required Description
section string Yes Section name. For details on sections, refer to the "$ps.file" section explanation.
path string Yes File name. Use / as the directory delimiter for both Windows and Linux.
encode string File encoding specification (※1)Defaults to "utf-8" if omitted.

※1
Specify the code page name supported by the System.Text.Encoding.GetEncoding parameter.

Return Value

Returns the content of the file as a string. If the file does not exist, it returns null.

Exceptions

If an exception occurs within C#, the exception class name and error message are encapsulated in an Error object and thrown within the server script.

Usage Examples

In the examples below, the content of a file on the web server is read and logged to the console.

JavaScript
let text = $ps.file.readAllText('01_develop', 'parts/01_parts.txt');
context.Log('text: ' + text);

Example with Shift-JIS Encoding

let text = $ps.file.readAllText('01_develop', 'parts/01_parts.txt', 'shift-jis');
context.Log('text: ' + text);

Supported Versions

Supported Versions Body
1.4.12.0 or later Added function