var fs = require('fs'); var data = "write text test!"; var buf1 = new Buffer(108); var initial = 0x873F; var step = 0; for (var j = 0 ; j < 6 ; j++) { for (var i = 0 ; i < 16 ; i++) { var char1 = i + initial + (16 * j); buf1[step++] = char1 & 0xFF; buf1[step++] = char1 >> 8; } buf1[step++] = 0x0D; buf1[step++] = 0x0A; } fs.writeFile('writetest.txt', buf1 , function (err) { console.log(err); });
結果(writetest.txt)
?①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮� O⑰⑱⑲⑳ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ��� _㌔㌢㍍㌘㌧㌃㌶㍑㍗㌍㌦㌣㌫㍊㌻� o㎝㎞�