中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何读取读取分布式路径下的文件
微信扫码分享
readFile(): void { this.appendix.forEach((item: AppendixBean) => { let filePath: string = this.distributedPath + item.fileName; let savePath: string = getContext().filesDir + '/' + item.fileName; try { while (fileIo.accessSync(filePath)) { let saveFile = fileIo.openSync(savePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); let file = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE); let buf: ArrayBuffer = new ArrayBuffer(CommonConstants.FILE_BUFFER_SIZE); let readSize = 0; let readLen = fileIo.readSync(file.fd, buf, { offset: readSize }); while (readLen > 0) { readSize += readLen; fileIo.writeSync(saveFile.fd, buf); readLen = fileIo.readSync(file.fd, buf, { offset: readSize }); } fileIo.closeSync(file); fileIo.closeSync(saveFile); break; } } catch (error) { let err: BusinessError = error as BusinessError; Logger.error(`DocumentViewPicker failed with err: ${JSON.stringify(err)}`); } }); }