use the fs.read () method of nodejs to read part of the txt file. The
buffer is set to 1024 bytes.
because one Chinese character occupies two bytes, occasionally the last Chinese character reads only one byte, resulting in garbled code
//
var fs = require("fs")
// 10240
var buf = new Buffer.alloc(1024,"utf8");
fs.open("text.txt", "r+", function(err,fd){
if(err) throw err
console.log("")
fs.read(fd, buf, 0, buf.length, 0, function(err, bytes){
if(err) throw err
console.log(bytes + " ");
//
if(bytes > 0){
console.log(":" + buf.slice(0, bytes).toString());
}
})
})