首页 > 解决方案 > 使用 NodeJS 将 .DEX 文件作为文本读取

问题描述

我目前正在编写一个脚本,该脚本将处理一些生成的 .dex 文件(来自另一个脚本)。当我使用时,fs.readFile(filename)我在终端中将其作为返回:

<Buffer 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 24 6e 61 6d 65 09 ... 3011 more bytes>

但是,如果我在 VsCode 或记事本中打开文件,它是完全可读的文本。有没有办法解析这个终端对原始文本的响应,或者它是一个库?

提前致谢

标签: javascriptnode.jsparsingdex

解决方案


使用 utf-8 编码

with readFile如果未指定编码,则返回原始缓冲区。

const fs = require("fs");

async function main(){
    const filePath = "./test.DEX";
    const encoding = "utf-8";
    
    const content = await fs.promises.readFile(filePath, encoding);

    console.log(content);
}

main();

推荐阅读