Not works fs.readFile in node js

后端 未结 5 777

I have:

 fs.readFile(\'../services/Prescipcion.xml\', \"utf8\", function (err, data) {
    console.log(\"err->\", err);
    console.log(\"data\", data);
 });
         


        
5条回答
  •  别跟我提以往
    2021-02-19 11:15

    A full example that worked for me, based on other answer

    var fs = require('fs');
    var path = require('path');
    var readStream = fs.createReadStream(path.join(__dirname, '../rooms') + '/rooms.txt', 'utf8');
    let data = ''
    readStream.on('data', function(chunk) {
        data += chunk;
    }).on('end', function() {
        console.log(data);
    });
    

提交回复
热议问题