抖音开放平台Logo
开发者文档
“/”唤起搜索
控制台
  • JavaScript API
  • C# API
  • API 概览
  • 初始化
  • 基础
  • 调试工具
  • 界面
  • 渲染
  • 数据缓存
  • PlayerPrefs
  • 文件
  • 获取文件管理器
  • 文件管理器
  • 文件流式读写
  • TTFileSystemManager
  • TTFileSystemManager.AppendFile
  • TTFileSystemManager.AppendFileSync
  • TTFileSystemManage.ReadDir
  • TTFileSystemManager.ReadDirSync
  • TTFileSystemManager.Truncate
  • TTFileSystemManager.TruncateSync
  • 设备
  • 网络
  • 系统
  • 媒体
  • 支付
  • 广告
  • 位置
  • 开放能力
  • 抖音云模块
  • TTFileSystemManager.AppendFileSync
    收藏
    我的收藏

    TTSDK 6.2.5 及以后版本支持该能力。
    在文件结尾追加内容,文件不存在时会新建。
    前提条件
    无
    业务背景
    无
    使用限制
    无
    注意事项
      •文件路径通过 Application.persistentDataPath 拼接。
      •目前 Native 方案下效果与 File.AppendAllText 一致,有复杂需求推荐自己实现。
    相关教程
    无

    语法

    public string AppendFileSync(string filePath, byte[] data); public string AppendFileSync(string filePath, string data, string encoding = "utf8")

    参数说明

    属性名
    类型
    默认值
    必填
    说明
    filePath
    string
    无
    是
    要追加写入的文件路径
    data
    byte[]
    无
    是
    要追加写入的二进制数据
    有一重载方法, 为追加字符串
    属性名
    类型
    默认值
    必填
    说明
    filePath
    string
    无
    是
    要追加写入的文件路径
    data
    string
    无
    是
    要追加写入的数据要追加写入的二进制数据
    encoding
    string
    utf8
    否
    指定写入文件的字符编码

    返回值

    ​
    类型
    说明
    string
    为空则表示写入成功,否则为失败,并带上失败信息

    错误码

    代码示例

    ​
    var text = "test"; var binData = Encoding.UTF8.GetBytes(text); var path = Path.Combine(Application.persistentDataPath, srcPathInput.text); var errMsg = ""; errMsg = TT.GetFileSystemManager().AppendFileSync(path, binData); errMsg = TT.GetFileSystemManager() .AppendFileSync(path, text, "utf8"); if (string.IsNullOrEmpty(errMsg)) { Debug.Log($"append file to {srcPathInput.text} succeed, data length: {binData.Length}"); } else { Debug.Log("AppendFileSync", errMsg); }
    ​