[英]Nodejs - Issue while reading html contents from text file
我想使用下面的代码从文本文件中读取html内容。在使用fs模块从文件中读取所有html标记时,它们被替换为一些垃圾字符。
有人可以帮助我了解我在做什么错吗?
enter code here
文件内容
<h2 class="mb30">Bone Grafting</h2>
响应
<h2 class="mb30">Bone Grafting</h2>
使用的代码
var fs = require('fs');
fs.readFile(filePath, function (err, contents) {
//some code here
}
文本文件的编码为utf-8
您缺少包含用于读取文件详细信息的文件格式的信息。
fs = require('fs')
fs.readFile('/etc/hosts', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
console.log(data);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.