- API 概览
- 开放能力
- 基础
- 渲染
- 设备
- 文件
- 位置
- 媒体
- 网络
- 游戏转发分享
- 实时语音
- 数据缓存
- 系统
- 广告
- 界面
- 支付
- Worker
FileSystemManager.copyFileSync收藏我的收藏
收藏
我的收藏基础库 1.15.0 开始支持本方法,这是一个同步方法。
同步复制文件。
前提条件 | 无 |
业务背景 | 无 |
使用限制 | 无 |
注意事项 | destPath 必须以 ttfile://user 开头。
|
相关教程 | 无 |
语法
FileSystemManager.copyFileSync(srcPath, destPath)
参数说明
srcPath
类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|
string | 是 | 源文件地址 | 1.15.0 |
destPath
类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|
string | 是 | 目标文件地址,必须以 ttfile://user 开头 | 1.15.0 |
返回值
无
错误码
errNo | errMsg | 说明 | 最低支持版本 |
---|---|---|---|
20000 | copyFileSync:fail srcPath is invalid | srcPath 参数错误 | 1.99.0 |
20000 | copyFileSync:fail destPath is invalid | destPath 参数错误 | 1.99.0 |
20001 | copyFileSync:fail param should be xxx, but got xxx | 参数校验错误 | 1.99.0 |
21101 | copyFileSync:fail permission denied, copyFileSync {srcPath_value} -> {destPath_value} | 无操作权限(源路径不可读/目标路径不可写) | 1.99.0 |
21102 | copyFileSync:fail operation not permitted, copyFileSync {srcPath_value} | path 类型不对(directory/file) | 1.99.0 |
21104 | copyFileSync:fail user dir saved file size limit exceeded | 超出 User 目录存储上限 | 1.99.0 |
代码示例
const fileSystemManager = tt.getFileSystemManager();
// 下载网络资源
tt.downloadFile({
url:
"https://s3.pstatp.com/toutiao/resource/developer/static/img/main-logo.8e3a839.png",
success(res) {
console.log("下载成功", res.tempFilePath);
try {
// 拷贝文件, destPath 目录必须以 `ttfile://user` 开头
fileSystemManager.copyFileSync(
res.tempFilePath,
`ttfile://user/logo.png`
);
console.log("拷贝成功");
} catch (err) {
console.log("拷贝失败", err);
}
},
fail(res) {
console.log("下载失败", res.errMsg);
},
});
该文档是否有帮助?
点击纠错