Nodejs File Read fs.readFile

Here you can find the source of fs.readFile

Method Source Code

var fs = require("fs");
var x = [];/*from   ww  w  .  j  av  a  2 s.  c o  m*/

for (var i = 0; i < 6; i++) {
    x.push([]);
    for (var j=0; j<50; j++) {
        x[i].push(" ");
    }
}


fs.readFile("l8.txt", "utf8", function (e, d) {
    var data = d.split("\n");
    for (var i = 0; i< data.length; i++) {
        if (data[i].indexOf("rect")!= -1) {
            var tmp = data[i].match(/\d+x\d+/)[0].split("x");
            console.log("rect: "+tmp);
            rect (x, parseInt(tmp[1]), parseInt(tmp[0]));
        } else if (data[i].indexOf("row")!= -1) {
            var tmp = data[i].match(/\d+/g);
            console.log("row: "+tmp);
            rotateRow(parseInt(tmp[0]), parseInt(tmp[1]));

        } else if(data[i].indexOf("column")!= -1) {
            var tmp = data[i].match(/\d+/g);
            console.log("column: "+tmp);
            rotateCol(parseInt(tmp[0]), parseInt(tmp[1]));
        }
        console.log(i);
        printMatrix(x);
    }
    count();
});

Related

  1. fs.readFile
    var fs = require('fs');
    fs.readFile('rule.txt', function(err, data){
      if (err) {console.log(err);return;}
      var data = data.toString();
      data = data.split(/\n|\r/g).trimNull();
      console.log(data);
    });