中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
先生成中文目录,在用fileIo.copyFileSync拷贝文件时,发现拷贝不了,异常捕获也没有报错。验证英文目录,就能正常拷贝。
微信扫码分享
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); } });