您需要先 登录 才能评论/回答
全部评论(1)
解决措施
读取文件内容的buffer数据后,通过TextDecoder对文件内容进行解码。
i
mport { util } from "@kit.ArkTS"
import { fileIo } from '@kit.CoreFileKit';
let filePath = getContext(this).filesDir + "/test0.txt";
let stream = fileIo.createStreamSync(filePath, "r+");
let buffer = new ArrayBuffer(4096);
let readOut = stream.readSync(buffer);
let textDecoder = util.TextDecoder.create('utf-8', { ignoreBOM: true });
let readString = textDecoder.decodeWithStream(new Uint8Array(buffer), { stream: false });
console.log("读取的文件内容:" + readString);
参考链接
TextDecoder
赞
2024-01-22 17:23:38