📌 从基础库 3.125.4 版本开始支持
参数 | 类型 | 说明 |
|---|---|---|
| srcPath | string | 源文件路径,支持本地路径 |
| destPath | string | 目标文件路径,支持本地路径 |
const fs = xhs.getFileSystemManager()
// 异步调用
fs.copyFile({
srcPath: `${xhs.env.USER_DATA_PATH}/hello.txt`,
destPath: `${xhs.env.USER_DATA_PATH}/hello_copy.txt`,
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})
// 同步接口
try {
fs.copyFileSync(
`${xhs.env.USER_DATA_PATH}/hello.txt`,
`${xhs.env.USER_DATA_PATH}/hello_copy.txt`
)
} catch(e) {
console.error(e)
}