格式
typescript
File.WriteAllBytes(path, data)所属类: File
描述
将内存流数据内容写入指定路径的文件中(覆盖原内容)。
参数
| 参数名 | 类型 | 描述 |
|---|---|---|
| path | string | 指定文件的路径 |
| data | MemoryStream | 内存流数据 |
返回值
| 类型 | 描述 |
|---|---|
boolean | 是否成功写入 |
代码示例
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 writed some bytes, but content is wrong: ", stream.GetString());
return;
}
} catch (error) {
Debug.Error(error);
}
}