Why does Node.js' fs.readFile() return a buffer instead of string?

后端 未结 6 971
梦毁少年i
梦毁少年i 2020-11-30 17:33

I\'m trying to read the content of test.txt(which is on the same folder of the Javascript source) and display it using this code:

var fs = requi         


        
6条回答
  •  旧巷少年郎
    2020-11-30 18:02

    Try:

        fs.readFile("test.txt", "utf8", function(err, data) {...});
    

    Basically, you need to specify the encoding.

提交回复
热议问题