📌 从基础库 3.125.4 版本开始支持
名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
| tempFilePath | string | 是 | 临时文件路径(本地路径) |
| filePath | string | 否 | 目标存储路径(不传则自动生成) |
string savedFilePath
存储后的文件绝对路径
function saveFileSync(tempFilePath, filePath = '') {
try {
const fs = xhs.getFileSystemManager()
// 调用 saveFileSync 保存文件
const savedFilePath = fs.saveFileSync(tempFilePath, filePath);
console.log('文件保存成功:', savedFilePath); // 存储后的文件路径
return savedFilePath; // 返回存储后的文件路径
} catch (err) {
console.error('文件保存失败:', err);
throw err; // 抛出错误以便调用方处理
}
}
// 调用示例
try {
const savedPath = saveFileSync('/path/to/temp/file.txt', '/path/to/save/file.txt');
console.log('保存的文件路径:', savedPath);
} catch (err) {
console.error('保存文件时出错:', err);
}