HarmonyOS fileIo.copyFileSync拷贝文件到中文目录,拷贝不了

先生成中文目录,在用fileIo.copyFileSync拷贝文件时,发现拷贝不了,异常捕获也没有报错。验证英文目录,就能正常拷贝。

HarmonyOS
2天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zbw_apple
let applicationContext = this.context.getApplicationContext();
let pathDir = applicationContext.filesDir;
let dirPath = pathDir + "/中文";
// let dirPath = pathDir + "/testDir";
fs.mkdir(dirPath).then(() => {
  console.info("mkdir succeed");
}).catch((err: BusinessError) => {
  console.error("mkdir failed with error message: " + err.message + ", error code: " + err.code);
});

getContext(this).resourceManager.getRawFileContent('test.txt', (_err, value) => {
  let myBuffer: ArrayBufferLike = value.buffer
  let context = getContext(this);
  //沙箱路径
  let filePath = context.filesDir + "/test.txt";
  console.log("testTag-filePath:" + filePath);
  let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
  let writeLen = fs.writeSync(file.fd, myBuffer);
  console.info("testTag-write data to file succeed and size is:" + writeLen);
  fs.closeSync(file);
  dirPath = dirPath + "/test.txt";
  try {
    fs.copyFileSync(filePath, dirPath);
  } catch (err) {
    console.log(err)
  }
  console.info("copyFileSync over------------");

  try {
    let res = fs.accessSync(dirPath);
    if (res) {
      console.info("file exists");
    } else {
      console.info("file not exists");
    }
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error("accessSync failed with error message: " + err.message + ", error code: " + err.code);
  }

});
分享
微博
QQ
微信
回复
2天前
相关问题
HarmonyOS选取并拷贝文件失败
414浏览 • 1回复 待解决
HarmonyOS pixelmap深拷贝问题
602浏览 • 1回复 待解决
HarmonyOS 如何对数组进行深拷贝
257浏览 • 1回复 待解决
HarmonyOS ArkWeb组件是否支持深拷贝
452浏览 • 2回复 待解决
HarmonyOS 数据库拷贝后无法读取
272浏览 • 1回复 待解决
ArkWeb组件是否支持深拷贝
519浏览 • 1回复 待解决
ArkTS中如何实现对象的深拷贝
441浏览 • 1回复 待解决