var fs = require('fs');
fs.readFile('file.txt', 'utf-8', function(err, data) {
if(err) {
console.error(err);
} else {
console.log(data);
}
});
console.log('end.');
var data2 = fs.readFileSync('file.txt', 'utf-8');
console.log(data2);
console.log('end.');
这段程序的执行结果为什么是
end.
Contents of the file.
end.
Contents of the file.
而不是下面这样的呢?
end.
Contents of the file.
Contents of the file.
end.