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
2024-09-09 12:24:30
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zxjiu

readLines是根据stat获取的文件大小去构建buffer,cpuinfo_min_freq文件的size是0,所以buffer是0,因此读出来的内容是0。根因是/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq这个文件stat出来的size是0,所以导致readLines对不到内容。

分享
微博
QQ
微信
回复
2024-09-09 16:30:15
相关问题
fs.mkdirSync报错:No such file or directory
2012浏览 • 1回复 待解决
报错Error while Deploying HAP。
12554浏览 • 2回复 待解决
冷启动报错Error message
2128浏览 • 1回复 待解决
app启动crash报错Error message:MainPage:
1793浏览 • 1回复 待解决
neptune 烧写报错[upload] Error -1
6361浏览 • 2回复 待解决
编译构建报错,提示CONFIGURE_SDK_ERROR
749浏览 • 1回复 待解决