格式
typescript
File.WriteAllText(path, content)所属类: File
描述
将文本内容写入指定路径的文件中(覆盖原内容)。
参数
| 参数名 | 类型 | 描述 |
|---|---|---|
| path | string | 指定文件的路径 |
| content | string | 文本内容 |
返回值
| 类型 | 描述 |
|---|---|
void |
代码示例
javascript
function Test(file_path: string) {
const text_content: string = "something\r\nnew line.\r\n中文\r\n\xC0\xDE\n\t";
try {
File.WriteAllText(file_path, text_content);
let content = File.ReadAllText(file_path);
if (content.length <= 0 || content != text_content) {
Debug.Error("File '", file_path, "' has been writed something, but content is blank.");
}
} catch (error) {
Debug.Error(error);
}
}