使用 NodeJS 将 .DEX 文件读取为文本
Read .DEX file as text using NodeJS
我目前正在编写一个脚本来处理一些生成的 .dex 文件(来自另一个脚本)。当我使用 fs.readFile(filename)
时,我在终端中将其显示为 return:
<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 或记事本中打开文件,它是完全可读的文本。有没有什么办法可以解析这个终端对原始文本的响应,或者它是一个库吗?
提前致谢
使用utf-8编码
和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();
我目前正在编写一个脚本来处理一些生成的 .dex 文件(来自另一个脚本)。当我使用 fs.readFile(filename)
时,我在终端中将其显示为 return:
<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 或记事本中打开文件,它是完全可读的文本。有没有什么办法可以解析这个终端对原始文本的响应,或者它是一个库吗?
提前致谢
使用utf-8编码
和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();