[英]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.