Skip to content

format

typescript
File.WriteAllBytes(path, data)

class: File

description

Write the content of a memory stream to a file at the specified path (overwrite the original content).

parameter

param_nametypedescription
pathstringThe path of the specified file.
dataMemoryStreamThe memory stream data.

return

typedescription
booleanWhether the write operation was successful.

code example

javascript
function Test(file_path: string) {  
    let bin_content: MemoryStream = new MemoryStream();
    const vector3 = new Vector3(12, 34, 56);
    bin_content.SetVector3(vector3);
    try {
        if (!File.WriteAllBytes(file_path, bin_content)) {
            Debug.Error("File '", file_path, "' write bytes failed.");
            return;
        }
        let stream = File.ReadAllBytes(file_path);
        let vector3_test = stream.GetVector3();
        if (stream.length <= 0 || !vector3_test.EqualsTo(vector3)) {
            stream.PrepareRead();
            Debug.Error("File '", file_path, "' has been written some bytes, but the content is wrong: ", stream.GetString());
            return;
        }
    } catch (error) {
        Debug.Error(error);
    }
}