HarmonyOS fs.readLines报错: Msg: No error information, ErrrorCode: 0
读取/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq文件。
1)使用fs.readLines报错,代码如下:
this.result = ""
let filePath = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq";
fs.readLines(filePath).then((readerIterator: fs.ReaderIterator) => {
for (let it = readerIterator.next(); !it.done; it = readerIterator.next()) {
this.result += it.value + "\n";
}
}).catch((err: BusinessError) => {
console.error("open file failed with error message: " + err.message + ", error code: " + err.code);
this.result = "错误: " + err.message + ", " + err.code
});
2)使用fs.open,可以执行:
let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
let arrayBuffer = new ArrayBuffer(4096);
fs.read(file.fd, arrayBuffer).then((readLen: number) => {
console.info("read file data succeed");
let buf = buffer.from(arrayBuffer, 0, readLen);
console.info(`The content of file: ${buf.toString()}`);
this.result = buf.toString();
}).catch((err: BusinessError) => {
this.result = "Error: " + err.message;
}).finally(() => {
fs.closeSync(file);
})
HarmonyOS
赞
收藏 0
回答 1
待解决
相关问题
HarmonyOS fs.rmdirSync报错:Directory not empty
20浏览 • 1回复 待解决
fs.mkdirSync报错:No such file or directory
2012浏览 • 1回复 待解决
编译报错hvigor ERROR: Error, Schema validate failed
1422浏览 • 1回复 待解决
HarmonyOS使用ArkTS提供的fs读文件,其中ReadTextOptions报错如下:
355浏览 • 1回复 待解决
HarmonyOS 相册选的图片 用fs读不到信息 报错13900002
905浏览 • 1回复 待解决
编译报错:hvigor ERROR: Error, Schema validate failed.
2658浏览 • 1回复 待解决
报错:Error while Deploying HAP。
12554浏览 • 2回复 待解决
冷启动报错Error message
2128浏览 • 1回复 待解决
HarmonyOS request.uploadFile 报错 empty error message
441浏览 • 1回复 待解决
HarmonyOS promptAction.showDialog报错:showDialog err: Error: Internal error. Can not get delegate
398浏览 • 1回复 待解决
小熊派烧录报错 errno=0x3611 errno=0x3612如何解决?
6122浏览 • 2回复 待解决
HarmonyOS IDE 编译报错:ArkTS ERROR:Duplicate identifier “index”
127浏览 • 1回复 待解决
HarmonyOS 使用Preferences时报错崩溃 Error code 15500000
821浏览 • 1回复 待解决
app启动crash报错Error message:MainPage:
1793浏览 • 1回复 待解决
neptune 烧写报错[upload] Error -1
6361浏览 • 2回复 待解决
运行HarmonyOS工程持续报错error: ACCESS_ERROR, code: 109.怎么回事啊?
4535浏览 • 2回复 待解决
报错error: install failed due to grant request permissions failed Error while Deploy Hap
2222浏览 • 0回复 待解决
OpenHarmony安装hap报错:error: install releaseType not same
3722浏览 • 1回复 待解决
调用imageSource.createPixelMap()报错“Create PixelMap error”
1961浏览 • 1回复 待解决
编译构建报错,提示CONFIGURE_SDK_ERROR
749浏览 • 1回复 待解决
#鸿蒙学习大百科#fs.open(filepath)时报错No such file or directory
455浏览 • 1回复 待解决
readLines是根据stat获取的文件大小去构建buffer,cpuinfo_min_freq文件的size是0,所以buffer是0,因此读出来的内容是0。根因是/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq这个文件stat出来的size是0,所以导致readLines对不到内容。