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_name | type | description |
|---|---|---|
| path | string | The path of the specified file. |
| data | MemoryStream | The memory stream data. |
return
| type | description |
|---|---|
boolean | Whether 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);
}
}