encoding is ignored in fs.readFile

后端 未结 2 591
日久生厌
日久生厌 2021-02-07 01:47

I am trying to read the contents of a properties file in node. this is my call:

fs.readFile(\"server/config.properties\", {encoding: \'utf8\'}, function(err, dat         


        
2条回答
  •  别那么骄傲
    2021-02-07 02:12

    Depending on the version of Node you're running, the argument may be just the encoding:

    fs.readFile("server/config.properties", 'utf8', function(err, data ) {
       console.log( data );
    });
    

    The 2nd argument changed to options with v0.10:

    • FS readFile(), writeFile(), appendFile() and their Sync counterparts now take an options object (but the old API, an encoding string, is still supported)

    For former documentation:

    • v0.8.22
    • v0.6.21

提交回复
热议问题