簡體   English   中英

Node.js-從文本文件讀取html內容時出現問題

[英]Nodejs - Issue while reading html contents from text file

我想使用下面的代碼從文本文件中讀取html內容。在使用fs模塊從文件中讀取所有html標記時,它們被替換為一些垃圾字符。

有人可以幫助我了解我在做什么錯嗎?

enter code here文件內容

<h2 class="mb30">Bone Grafting</h2>

響應

&lt;h2 class&#x3D;&quot;mb30&quot;&gt;Bone Grafting&lt;&#x2F;h2&gt;

使用的代碼

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM